@sayjava/deputy
v0.6.3
Published
Deputy is a robust HTTP(s) mocking sever suitable for api stubbing in development and testing. Declarative and HTTP based APIs, automatic proxying and sequence diagraming
Downloads
13
Maintainers
Readme
What is Deputy?
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"
}
]
}
}
]
Quick Start
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
Features
- 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
Examples
Programitcally
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'));
Usage Scenarios
Here are some setup scenarios that deputy can be used to aid development and testing
Transparently Mock & Forward API requests
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
Application Testing
Simulate complex HTTP requests and response scenarios in test environments
see the Mock Guide
Deputy UI
By default, Deputy server can be reached at http://localhost:8081
.
Logs View
View and inspect http requests and responses from the Logs interface in realtime as requests are received
Visualize
Deputy automatically creates a sequence diagram of requests it receives
Mocking Interface
Mocks can be imported, exported, edited, cloned, disabled, and enabled from Deputy UI