The easiest and quickest way to mock HTTP endpoints for development and testing purposes
Deputy is an HTTP API mocking server that can aid in rapid application development by mocking endpoints and configuring responses from configurations.
Deputy can also act as a testing server to validate what requests made by system under test.
Here is a sample mock definition
[
{
"request": {
"path": "/user/(\\d+)/slug/(.*)",
"params": {
"output_type": "json|xml"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"id": "slug-id",
"content": "The post content"
}
]
}
}
]
With nodejs
npx @sayjava/deputy
With docker
docker run -p 8080:8080 -p 8081:8081 ghcr.io/sayjava/deputy
and test a sample endpoint
curl http://localhost:8080/who-am-i
- Declarative request matching and response
- Regex based request matching (request path, headers and body matchers)
- Alternate and limit responses on same request
- HTTP request validations
- Simulate response delays and network failures
- Inspect HTTP Requests and Response in realtime
const express = require('express');
const { createExpressMiddleware } = require('@sayjava/deputy');
// mount the mock on a middleware endpoint
const app = express();
app.use('/api', createExpressMiddleware({ mocksFolder: 'fixtures' }));
app.listen(3000, () => console.log('server started'));
Here are some setup scenarios that deputy can be used to aid development and testing
Simulate unready APIs by mocking some APIs and have other requests transparently forwarded to remote APIs See the examples/commerce folder using that uses the next/commerce + deputy
Simulate complex HTTP requests and response scenarios in test environments
see the Mock Guide
By default, Deputy server can be reached at http://localhost:8081
.
View and inspect http requests and responses from the Logs interface in realtime as requests are received
Deputy automatically creates a sequence diagram of requests it receives
Mocks can be imported, exported, edited, cloned, disabled, and enabled from Deputy UI