@sayjava/deputy

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

Usage no npm install needed!

<script type="module">
  import sayjavaDeputy from 'https://cdn.skypack.dev/@sayjava/deputy';
</script>

README

Deputy

The easiest and quickest way to mock HTTP endpoints for development and testing purposes

Explore deputy docs »

Quick Start » Guide » API »

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.

Dev

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

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

Dev

Application Testing

Simulate complex HTTP requests and response scenarios in test environments

Test

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

Logs

Visualize

Deputy automatically creates a sequence diagram of requests it receives

Visualize

Mocking Interface

Mocks can be imported, exported, edited, cloned, disabled, and enabled from Deputy UI

Mocking Interface

Full Documentation

Full Documentation