#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
- In the Qodex collection, go to About > About info
- 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
-
About - About info GET {{base_url}}/about
-
Mock-Collections - Show collections GET {{base_url}}/mock/collections
-
Mock-Custom Route Variants - Use route variant POST {{base_url}}/mock/custom-route-variants
-
Mock-Custom Route Variants - Restore route variants DELETE {{base_url}}/mock/custom-route-variants
-
Mock-Variants - Show variant details GET {{base_url}}/mock/variants/:variant_id
-
Config - Show config GET {{base_url}}/config
-
Config - Update config PATCH {{base_url}}/config
-
Alerts - Show alerts GET {{base_url}}/alerts
-
Alerts - Show alert details GET {{base_url}}/alerts/:alert_id
-
Mock-Routes - Show routes GET {{base_url}}/mock/routes