https://github.com/sayjava/deputy
http mocking, assert and proxy server for development and testing
https://github.com/sayjava/deputy
api-mock http-mock http-stub mock-server mocking-server stubbing
Last synced: 9 months ago
JSON representation
http mocking, assert and proxy server for development and testing
- Host: GitHub
- URL: https://github.com/sayjava/deputy
- Owner: sayjava
- License: unlicense
- Created: 2021-09-23T10:43:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-12T14:35:14.000Z (about 3 years ago)
- Last Synced: 2025-03-23T07:22:50.049Z (9 months ago)
- Topics: api-mock, http-mock, http-stub, mock-server, mocking-server, stubbing
- Language: TypeScript
- Homepage:
- Size: 6.5 MB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Deputy
The easiest and quickest way to mock HTTP endpoints for development and testing purposes
# 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
```json
[
{
"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
```shell
npx @sayjava/deputy
```
With docker
```shell
docker run -p 8080:8080 -p 8081:8081 ghcr.io/sayjava/deputy
```
and test a sample endpoint
```shell
curl http://localhost:8080/who-am-i
```
## Features
- [Declarative request matching and response](https://sayjava.github.io/deputy/guide)
- [Regex based request matching](https://sayjava.github.io/deputy/guide) (request path, headers and body matchers)
- [Alternate and limit responses on same request](https://sayjava.github.io/deputy/guide)
- [HTTP request validations](https://sayjava.github.io/deputy/assertions)
- [Simulate response delays and network failures](https://sayjava.github.io/deputy/guide)
- [Inspect HTTP Requests and Response in realtime](https://sayjava.github.io/deputy/start)
## Examples
- [with-nextjs-commerce](examples/with-nextjs-commerce)
- [with-nextjs-middleware](examples/with-nextjs-commerce)
## Programitcally
```javascript
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](next/commerces) + deputy

### Application Testing
Simulate complex HTTP requests and response scenarios in test environments

see the [Mock Guide](http://sayjava.github.io/deputy/mocking)
## 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

### Full Documentation
[Full Documentation](https://sayjava.github.io/deputy)