REST API integration
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.
The administration API is started on a different server of the API mock. By default, it is started in the 3110
port, but this can be changed using configuration.
Postman collection
Once Mocks Server is running, you can use our Postman public collection to interact with the administration API:
Swagger
Available API resources are described in the OpenAPI specification provided by the API server itself at http://localhost:3110/docs/openapi.json.
Start Mocks Server and browse to http://localhost:3110/docs to check out the API Swagger UI.
Javascript API client
A JavaScript client for the administration api is also distributed as a separated package: @mocks-server/admin-api-client.
Examples
Get collections
curl http://localhost:3110/api/mock/collections
Change the current collection
curl -X PATCH -d '{"mock":{"collections":{"selected":"collection-b"}}}' -H 'Content-Type: application/json' http://localhost:3110/api/config
Configuration
You can use the next Mocks Server configuration properties to change the API configuration:
plugins.adminApi.port
(Number): Port for the administration REST API. Default is3110
.plugins.adminApi.host
(String): Host for the administration REST API. Default is0.0.0.0
(Reachable to all IPv4 addresses on the local machine).plugins.adminApi.https.enabled
(Boolean): Enables the HTTPS protocol in the administration REST API. For further information read the "Enabling HTTPS" guide.plugins.adminApi.https.cert
(String): Path to the HTTPS certificate. Relative to the currentprocess.cwd()
or absolute.plugins.adminApi.https.key
(String): Path to the HTTPS certificate key. Relative to the currentprocess.cwd()
or absolute.
Learn more about how to set Mocks Server settings in the configuration chapter