@mocks-server/admin-api-client-data-provider
v6.1.3
Published
Client of @mocks-server/plugin-admin-api built with @data-provider
Downloads
8
Maintainers
Readme
Mocks-server administration api client built with @data-provider
This package provides an API client for administrating Mocks Server through HTTP requests to the Admin API plugin.
Built using data-provider
, it can be used in Node.js, browsers, and it is also compatible with other data-provider
packages, such as @data-provider/react
, so it can be easily integrated in other ecosystems.
Installation
npm i --save redux @data-provider/core @data-provider/axios @mocks-server/admin-api-client-data-provider
Usage with promises
All methods described in the Api return Promises when executed (except the configClient
method):
import { about, config } from "@mocks-server/admin-api-client-data-provider";
const example = async () => {
const { version } = await about.read();
console.log(`Current plugin-admin-api version is ${version}`);
const currentConfig = await config.read();
console.log("Current mocks-server config is", JSON.stringify(currentConfig));
await config.update({
mock: {
collections: {
selected: "user-super-admin",
},
routes: {
delay: 1000,
},
},
});
console.log("Collection and delay changed");
};
example();
Usage with data-provider
All exported properties are @data-provider/axios
providers, so can be used to define @data-provider Selectors. Methods can also be connected to frameworks using another data-provider
packages, such as @data-provider/react
.
Api
about.read()
- Returns info about current version of Mocks Server and plugins.config.read()
- Returns current Mocks Server config.config.update(configObject)
- Updates Mocks Server config. A configuration object has to be provided. Read the Mocks Server configuration documentation for further info.alerts.read()
- Returns current alerts.alert.queries.byId(id).read()
- Returns an alert by ID.collections.read()
- Returns available collections.collection.queries.byId(mockId).read()
- Returns a specific mock.routes.read()
- Returns available routes.route.queries.byId(id).read()
- Returns a route by id.variants.read()
- Returns available route variants.variant.queries.byId(id).read()
- Returns an specific route variant.customRouteVariants.read()
- Returns current custom route variants.customRouteVariants.create(id)
- Sets a specific route variant to be used by current collection.customRouteVariants.delete()
- Restore route variants to those defined in the current collection.
Configuration
By default, the client is configured to request to http://127.0.0.1:3110/api, based in the default options of Mocks Server admin API plugin
You can change the port, host and protocol using the configClient
method:
import { configClient } from "@mocks-server/admin-api-client-data-provider";
configClient({
port: 3500,
host: "localhost",
protocol: "https",
});
Release notes
Current major release is compatible only with @mocks-server/main
versions upper or equal than 3.6
. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update @mocks-server/main
, you can also use any 5.x
version of this package with any @mocks-server/[email protected]
version.
Contributing
Contributors are welcome. Please read the contributing guidelines and code of conduct.