#Admin API

Number of APIs: 14

Mocks Server administration API

Preface

The Mocks Server main distribution includes the admin-api plugin preinstalled. It provides a REST API allowing to interact with the server while it is running.

You can use this collection to interact with the administration API and change the Mock Server settings while it is running, which may be very useful while using Mocks Server for development, for example.

Using it, you can change the current Mocks Server collection, define custom route variants, change the mock delay, etc.

Step 1: Install and start mocks-server

Add it to your project dependencies using NPM:


npm i -D @mocks-server/main




Add the next script to the package.json file:


{
  "scripts": {
    "mocks" : "mocks-server"
  }
}




Run the next NPM command:


npm run mocks




For further info about installing Mocks Server visit https://www.mocks-server.org/docs/installation

Step 2: Make your first API call

  1. In the Qodex collection, go to About > About info
  2. Click the Send button to get the response

Extra: Configuration

The Qodex collection variables are set to match the default Mocks Server Admin API configuration, so you don't have to change anything until you changed the host or port options of the adminApi plugin. In that case, change the correspondent collection variables to fit your configuration.

For example, if you changed the plugins.adminApi.port option to 3200, set the port collection variable to 3200 as well.

Example

Change plugins.adminApi.port in Mocks Server:


npm run mocks -- --plugins.adminApi.port=3200




Change the port variable in Qodex collection:

  • Variables tab > port variable > Set Current value to 3200
  1. About - About info GET {{base_url}}/about

  2. Mock-Collections - Show collections GET {{base_url}}/mock/collections

  3. Mock-Custom Route Variants - Use route variant POST {{base_url}}/mock/custom-route-variants

  4. Mock-Custom Route Variants - Restore route variants DELETE {{base_url}}/mock/custom-route-variants

  5. Mock-Variants - Show variant details GET {{base_url}}/mock/variants/:variant_id

  6. Config - Show config GET {{base_url}}/config

  7. Config - Update config PATCH {{base_url}}/config

  8. Alerts - Show alerts GET {{base_url}}/alerts

  9. Alerts - Show alert details GET {{base_url}}/alerts/:alert_id

  10. Mock-Routes - Show routes GET {{base_url}}/mock/routes