Getting Started

tests GitHub license codecov npm npm Docker Pulls mockhttp.org

A simple HTTP server for mocking responses in tests. Inspired by httpbin and built with Node.js and Fastify. Run it at mockhttp.org, with Docker (jaredwray/mockhttp), or in Node.js (npm install @jaredwray/mockhttp).

Table of Contents

Features

  • All the features of httpbin
  • Taps — inject custom responses for testing and development
  • Bins — capture and inspect incoming HTTP requests (great for webhook debugging)
  • @fastify/helmet built in by default
  • Built with Node.js, TypeScript, and Fastify
  • Deploy via Docker or Node.js
  • Free hosted service at mockhttp.org, running on Cloudflare
  • Documentation site and interactive OpenAPI reference
  • Auto-detect the next port that is not in use
  • HTTPS and HTTP/2, plus rate limiting, logging, and URL matching

Deploy via Docker

docker run -d -p 3000:3000 jaredwray/mockhttp

Deploy via Docker Compose

services:
  mockhttp:
    image: jaredwray/mockhttp:latest
    ports:
      - "3000:3000"

If you want to run it on a different port, just change the 3000 to whatever port you want and add in the environment variable PORT to the environment.

services:
  mockhttp:
    image: jaredwray/mockhttp:latest
    ports:
      - "3001:3001"
    environment:
      - PORT=3001

You can see an example of this in the docker-compose.yaml file.

Deploy via Node.js

npm install @jaredwray/mockhttp --save

then run mockhttp in your code.

import { MockHttp } from '@jaredwray/mockhttp';
const mock = new MockHttp();
await mock.start(); // start the server
const response = await fetch('http://localhost:3000/get');
console.log(response);
await mock.close(); // stop the server
Edit this page