Numbers Prefer Multiplication
Miss any of our Open RFC calls?Watch the recordings here! »

@mocks-server/admin-api-client

2.0.4 • Public • Published

Build status Coverage Status Quality Gate

NPM dependencies Renovate Last commit Last release

NPM downloads License

Mocks-server administration api client

This package contains methods for administrating the mocks-server (through the @mocks-server/plugin-admin-api REST API).

Requests to the @mocks-server are made using cross-fetch, which makes this package compatible with browsers and nodejs environments, but, if you are going to build a browser application, you'll probably prefer to use the @mocks-server/admin-api-client-data-provider package, which uses @data-provider, and works well with Redux, React, etc.

Install

npm install --save @mocks-server/admin-api-client

The UMD build is also available on unpkg:

<script src="https://unpkg.com/@mocks-server/admin-api-paths/dist/index.umd.js"></script>
<script src="https://unpkg.com/@mocks-server/admin-api-client/dist/index.umd.js"></script>

The umd distribution is bundled with the "cross-env" dependency, but requires the "@mocks-server/admin-api-paths" dependency to be added separately.

Usage

All methods described in the Api (expect the config method) return Promises when executed:

import { about, settings } from "@mocks-server/admin-api-client";
 
const example = async () => {
  const { version } = await about.read();
  console.log(`Current plugin-admin-api version is ${version}`);
 
  const currentSettings = await settings.read();
  console.log("Current mocks-server settings are", currentSettings);
 
  await settings.update({
    behavior: "user-super-admin",
    delay: 1000
  });
  console.log("Behavior and delay changed");
};
 
example();

Api

  • about.read() - Returns info about mocks-server/plugin-admin-api, such as current version.
  • settings.read() - Returns current @mocks-server settings.
  • settings.update(settingsObject) - Updates @mocks-server settings. A settings object has to be provided. Read the @mocks-server configuration documentation for further info.
  • behaviors.read() - Returns collection of available behaviors.
  • behavior(behaviorName).read() - Returns an specific behavior.
  • fixtures.read() - Returns collection of available fixtures.
  • fixture(fixtureId).read() - Returns an specific fixture.

Configuration

By default, the client is configured to request to http://localhost:3100/admin, based in the default options of @mocks-server

You can change both the base url of the "@mocks-server", and the base api path of the "@mocks-server/plugin-admin-api" using the config method:

import { config } from "@mocks-server/admin-api-client";
 
config({
  apiPath: "/foo-admin",
  baseUrl: "http://my-mocks-server:3000"
});

Contributing

Contributors are welcome. Please read the contributing guidelines and code of conduct.

Install

npm i @mocks-server/admin-api-client

DownloadsWeekly Downloads

664

Version

2.0.4

License

MIT

Unpacked Size

27.8 kB

Total Files

7

Last publish

Collaborators

  • avatar