npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mocks-server/admin-api-client-data-provider

v6.1.3

Published

Client of @mocks-server/plugin-admin-api built with @data-provider

Downloads

20

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.