7.0.1 • Published 11 months ago

@mocks-server/admin-api-client v7.0.1

Weekly downloads
695
License
MIT
Repository
github
Last release
11 months ago

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 Mocks Server (using the Admin API plugin under the hood).

Requests to the Mocks Server API 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 (except the config method) return Promises when executed:

import { readAbout, readSettings, updateSettings } from "@mocks-server/admin-api-client";

const example = async () => {
  const { version } = await readAbout();
  console.log(`Current Admin API plugin version is ${version}`);

  const currentSettings = await readSettings();
  console.log("Current Mocks Server settings are", currentSettings);

  await updateSettings({
    mock: "user-super-admin",
    delay: 1000
  });
  console.log("Mock and delay changed");
};

example();

Api

  • readAbout() - Returns info about the Admin API plugin, such as current version.
  • readSettings() - Returns current Mocks Server settings.
  • updateSettings(settingsObject) - Updates Mocks Server settings. A settings object has to be provided. Read the Mocks Server configuration docs for further info.
  • readAlerts() - Returns array of current alerts.
  • readAlert(alertId) - Returns an specific alert.
  • readMocks() - Returns available mocks.
  • readMock(id) - Returns data of a specific mock.
  • readRoutes() - Returns available routes.
  • readRoute(id) - Returns data of a specific route.
  • readRoutesVariants() - Returns available routes variants.
  • readRouteVariant(id) - Returns data of a specific route variant.
  • readMockCustomRoutesVariants() - Returns current routes variants manually added to current mock.
  • addMockCustomRouteVariant(id) - Add a route variant to current mock.
  • restoreMockRoutesVariants() - Restore current mock original routes variants.
Legacy methods
  • readBehaviors() - Returns collection of available behaviors.
  • readBehavior(behaviorName) - Returns an specific behavior.
  • readFixtures() - Returns collection of available fixtures.
  • readFixture(fixtureId) - 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 Mocks Server, and the base api path of the Admin API plugin 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.

7.0.1

11 months ago

8.0.0-beta.2

11 months ago

8.0.0-beta.1

11 months ago

7.0.0

2 years ago

5.0.2

2 years ago

6.1.0

2 years ago

6.0.0

2 years ago

6.2.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.1.0

3 years ago

3.0.0

3 years ago

3.0.0-beta.2

3 years ago

3.0.0-beta.1

3 years ago

2.1.0

3 years ago

2.0.5

3 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago