Package Exports
- @mocks-server/admin-api-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mocks-server/admin-api-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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.