{"id":19282045,"url":"https://github.com/jaredwray/mockhttp","last_synced_at":"2026-05-18T22:18:46.645Z","repository":{"id":261324186,"uuid":"883932324","full_name":"jaredwray/mockhttp","owner":"jaredwray","description":"A simple HTTP server that can be used to mock HTTP responses for testing purposes. Inspired by httpbin and built using nodejs and fastify with the idea of running it via https://mockhttp.org, via docker jaredwray/mockhttp, or nodejs npm install jaredwray/mockhttp.","archived":false,"fork":false,"pushed_at":"2025-04-05T18:04:43.000Z","size":256,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T08:01:19.362Z","etag":null,"topics":["fastify","http","httpbin","https","mock","mock-server","nodejs"],"latest_commit_sha":null,"homepage":"https://mockhttp.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredwray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-05T20:42:08.000Z","updated_at":"2025-04-05T18:04:47.000Z","dependencies_parsed_at":"2024-11-05T23:35:43.569Z","dependency_job_id":null,"html_url":"https://github.com/jaredwray/mockhttp","commit_stats":null,"previous_names":["jaredwray/mockhttp"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fmockhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fmockhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fmockhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredwray%2Fmockhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredwray","download_url":"https://codeload.github.com/jaredwray/mockhttp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248182083,"owners_count":21060893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","http","httpbin","https","mock","mock-server","nodejs"],"created_at":"2024-11-09T21:25:13.147Z","updated_at":"2026-05-18T22:18:46.632Z","avatar_url":"https://github.com/jaredwray.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![public/logo.svg](public/logo.svg)](https://mockhttp.org)\n\n[![tests](https://github.com/jaredwray/mockhttp/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/mockhttp/actions/workflows/tests.yaml)\n[![GitHub license](https://img.shields.io/github/license/jaredwray/mockhttp)](https://github.com/jaredwray/mockhttp/blob/master/LICENSE)\n[![codecov](https://codecov.io/gh/jaredwray/mockhttp/graph/badge.svg?token=eqtqoA3olU)](https://codecov.io/gh/jaredwray/mockhttp)\n[![npm](https://img.shields.io/npm/dm/@jaredwray/mockhttp)](https://npmjs.com/package/@jaredwray/mockhttp)\n[![npm](https://img.shields.io/npm/v/@jaredwray/mockhttp)](https://npmjs.com/package/@jaredwray/mockhttp)\n[![Docker Pulls](https://img.shields.io/docker/pulls/jaredwray/mockhttp)](https://hub.docker.com/r/jaredwray/mockhttp)\n[![mockhttp.org](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fjaredwray.com%2Fapi%2Fmockhttp-traffic\u0026query=%24.message\u0026label=mockhttp.org)](https://mockhttp.org)\n\nA simple HTTP server that can be used to mock HTTP responses for testing purposes. Inspired by [httpbin](https://httpbin.org/) and built using `nodejs` and `fastify` with the idea of running it via https://mockhttp.org, via docker `jaredwray/mockhttp`, or nodejs `npm install @jaredwray/mockhttp`.\n\n# Features\n* All the features of [httpbin](https://httpbin.org/)\n* Taps - Inject custom responses for testing and development\n* `@fastify/helmet` built in by default\n* Built with `nodejs`, `typescript`, and `fastify`\n* Deploy via `docker` or `nodejs`\n* Global deployment via [mockhttp.org](https://mockhttp.org) (free service)\n* Better API documentation and examples\n* Auto detect the port that is not in use\n* Maintained and updated regularly!\n\n# Table of Contents\n- [Deploy via Docker](#deploy-via-docker)\n- [Deploy via Docker Compose](#deploy-via-docker-compose)\n- [Deploy via NodeJS](#deploy-via-nodejs)\n- [HTTPS Support](#https-support)\n- [HTTP/2 Support](#http2-support)\n- [Response Injection (Tap Feature)](#response-injection-tap-feature)\n- [Rate Limiting](#rate-limiting)\n- [Logging](#logging)\n- [Flexible URL Matching](#flexible-url-matching)\n- [API Reference](#api-reference)\n- [About mockhttp.org](#about-mockhttporg)\n- [Contributing](#contributing)\n- [License](#license)\n\n# Deploy via Docker\n```bash\ndocker run -d -p 3000:3000 jaredwray/mockhttp\n```\n\n# Deploy via Docker Compose\n```yaml\nservices:\n  mockhttp:\n    image: jaredwray/mockhttp:latest\n    ports:\n      - \"3000:3000\"\n```\n\nIf 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.\n\n```yaml\nservices:\n  mockhttp:\n    image: jaredwray/mockhttp:latest\n    ports:\n      - \"3001:3001\"\n    environment:\n      - PORT=3001\n```\n\nYou can see an example of this in the [docker-compose.yaml](docker-compose.yaml) file.\n\n# Deploy via NodeJS\n```bash\nnpm install @jaredwray/mockhttp --save\n```\n\nthen run `mockhttp` in your code.\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\nconst mock = new MockHttp();\nawait mock.start(); // start the server\nconst response = await fetch('http://localhost:3000/get');\nconsole.log(response);\nawait mock.close(); // stop the server\n```\n\n# HTTPS Support\n\nMockHttp supports HTTPS with auto-generated self-signed certificates or your own custom certificates. No external dependencies are required — certificate generation uses only Node.js built-in `crypto`.\n\n## Auto-Generated Certificate\n\nThe simplest way to enable HTTPS is to pass `https: true`. A self-signed certificate for `localhost` is generated automatically:\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\n\nconst mock = new MockHttp({ https: true });\nawait mock.start();\n\nconsole.log(mock.isHttps); // true\n\n// Use Fastify's built-in inject() for testing (no TLS setup needed)\nconst response = await mock.server.inject({ method: 'GET', url: '/get' });\nconsole.log(response.statusCode); // 200\n\nawait mock.close();\n```\n\n\u003e **Note:** Self-signed certificates are not trusted by default. When making real HTTPS requests (e.g. with `fetch`), set `NODE_TLS_REJECT_UNAUTHORIZED=0` in your test environment or use a custom HTTPS agent.\n\n## Custom Certificate Options\n\nYou can customize the auto-generated certificate by passing `certificateOptions`:\n\n```javascript\nconst mock = new MockHttp({\n  https: {\n    certificateOptions: {\n      commonName: 'my-test-server',\n      validityDays: 30,\n      keySize: 4096,\n      altNames: [\n        { type: 'dns', value: 'example.local' },\n        { type: 'dns', value: '*.example.local' },\n        { type: 'ip', value: '192.168.1.100' },\n      ],\n    },\n  },\n});\n\nawait mock.start();\n// Make requests...\nawait mock.close();\n```\n\n## Provide Your Own Certificate\n\nYou can supply your own PEM-encoded certificate and key, either as strings or file paths:\n\n```javascript\n// Using PEM strings\nconst mock = new MockHttp({\n  https: {\n    cert: '-----BEGIN CERTIFICATE-----\\n...',\n    key: '-----BEGIN PRIVATE KEY-----\\n...',\n  },\n});\nawait mock.start();\n// Make requests...\nawait mock.close();\n```\n\n```javascript\n// Using file paths\nconst mock = new MockHttp({\n  https: {\n    cert: '/path/to/cert.pem',\n    key: '/path/to/key.pem',\n  },\n});\nawait mock.start();\n// Make requests...\nawait mock.close();\n```\n\n## Standalone Certificate Generation\n\nYou can also generate certificates independently using the exported utility functions:\n\n```javascript\nimport { generateCertificate, generateCertificateFiles } from '@jaredwray/mockhttp';\n\n// Generate in-memory PEM strings\nconst { cert, key } = generateCertificate({\n  commonName: 'my-app',\n  validityDays: 90,\n});\n\n// Generate and write to disk\nconst result = await generateCertificateFiles({\n  certPath: './certs/cert.pem',\n  keyPath: './certs/key.pem',\n  commonName: 'my-app',\n});\n```\n\n## HTTPS Options Reference\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `cert` | string | — | PEM-encoded certificate string or file path |\n| `key` | string | — | PEM-encoded private key string or file path |\n| `autoGenerate` | boolean | `true` | Auto-generate a self-signed certificate when cert/key are not provided |\n| `certificateOptions` | CertificateOptions | — | Options for the auto-generated certificate |\n\n### Certificate Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `commonName` | string | `'localhost'` | Certificate subject Common Name (CN) |\n| `altNames` | Array\\\u003c{ type, value }\\\u003e | `[dns:localhost, ip:127.0.0.1, ip:::1]` | Subject Alternative Names with type `'dns'` or `'ip'` |\n| `validityDays` | number | `365` | Certificate validity period in days |\n| `keySize` | number | `2048` | RSA key size in bits |\n\n# HTTP/2 Support\n\nMockHttp supports HTTP/2 in two modes:\n- **h2** — HTTP/2 over TLS (used by browsers), enabled with both `http2: true` and `https: true`\n- **h2c** — HTTP/2 cleartext (no TLS), enabled with just `http2: true`, useful for service-to-service testing\n\n## HTTP/2 over TLS (h2)\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\n\nconst mock = new MockHttp({ http2: true, https: true });\nawait mock.start();\n\nconsole.log(mock.http2); // true\nconsole.log(mock.isHttps); // true\n\nconst response = await mock.server.inject({ method: 'GET', url: '/get' });\nconsole.log(response.statusCode); // 200\n\nawait mock.close();\n```\n\nBy default, HTTP/1.1 clients can still connect via ALPN negotiation (`http1` defaults to `true`). To disable HTTP/1.1 fallback:\n\n```javascript\nconst mock = new MockHttp({ http2: true, https: true, http1: false });\nawait mock.start();\n```\n\n## HTTP/2 Cleartext (h2c)\n\n```javascript\nconst mock = new MockHttp({ http2: true });\nawait mock.start();\n\nconsole.log(mock.http2); // true\n\nawait mock.close();\n```\n\n\u003e **Note:** Browsers do not support h2c. This mode is useful for testing gRPC or service-to-service communication.\n\n## HTTP/2 via Environment Variable\n\n```bash\nHTTP2=true node your-app.js\n```\n\n# Response Injection (Tap Feature)\n\nThe injection/tap feature allows you to \"tap into\" the request flow and inject custom responses for specific requests. This is particularly useful for:\n- **Offline testing** - Mock external API responses without network access\n- **Testing edge cases** - Simulate errors, timeouts, or specific response scenarios\n- **Development** - Work on your application without depending on external services\n\n## What is a \"Tap\"?\n\nA \"tap\" is a reference to an injected response, similar to \"wiretapping\" - you're intercepting requests and returning predefined responses. Each tap can be removed when you're done with it, restoring normal server behavior.\n\n## Basic Usage\n\n```javascript\nimport { mockhttp } from '@jaredwray/mockhttp';\n\nconst mock = new mockhttp();\nawait mock.start();\n\n// Inject a simple response\nconst tap = mock.taps.inject(\n  {\n    response: \"Hello, World!\",\n    statusCode: 200,\n    headers: { \"Content-Type\": \"text/plain\" }\n  },\n  {\n    url: \"/api/greeting\",\n    method: \"GET\"\n  }\n);\n\n// Make requests - they will get the injected response\nconst response = await fetch('http://localhost:3000/api/greeting');\nconsole.log(await response.text()); // \"Hello, World!\"\n\n// Remove the injection when done\nmock.taps.removeInjection(tap);\n\nawait mock.close();\n```\n\n## Advanced Examples\n\n### Inject JSON Response\n\n```javascript\nconst tap = mock.taps.inject(\n  {\n    response: { message: \"Success\", data: { id: 123 } },\n    statusCode: 200\n  },\n  { url: \"/api/users/123\" }\n);\n```\n\n### Wildcard URL Matching\n\n```javascript\n// Match all requests under /api/\nconst tap = mock.taps.inject(\n  {\n    response: \"API is mocked\",\n    statusCode: 503\n  },\n  { url: \"/api/*\" }\n);\n```\n\n### Multiple Injections\n\n```javascript\nconst tap1 = mock.taps.inject(\n  { response: \"Users data\" },\n  { url: \"/api/users\" }\n);\n\nconst tap2 = mock.taps.inject(\n  { response: \"Posts data\" },\n  { url: \"/api/posts\" }\n);\n\n// View all active injections\nconsole.log(mock.taps.injections); // Map of all active taps\n\n// Remove specific injections\nmock.taps.removeInjection(tap1);\nmock.taps.removeInjection(tap2);\n```\n\n### Match by HTTP Method\n\n```javascript\n// Only intercept POST requests\nconst tap = mock.taps.inject(\n  { response: \"Created\", statusCode: 201 },\n  { url: \"/api/users\", method: \"POST\" }\n);\n```\n\n### Match by Headers\n\n```javascript\nconst tap = mock.taps.inject(\n  { response: \"Authenticated response\" },\n  {\n    url: \"/api/secure\",\n    headers: {\n      \"authorization\": \"Bearer token123\"\n    }\n  }\n);\n```\n\n### Catch-All Injection\n\n```javascript\n// Match ALL requests (no matcher specified)\nconst tap = mock.taps.inject({\n  response: \"Server is in maintenance mode\",\n  statusCode: 503\n});\n```\n\n### Dynamic Function Response\n\nYou can provide a function that dynamically generates the response based on the incoming request:\n\n```javascript\n// Function response with access to the request object\nconst tap = mock.taps.inject(\n  (request) =\u003e {\n    return {\n      response: {\n        message: `You requested ${request.url}`,\n        method: request.method,\n        timestamp: new Date().toISOString()\n      },\n      statusCode: 200,\n      headers: {\n        \"X-Request-Path\": request.url\n      }\n    };\n  },\n  { url: \"/api/*\" }\n);\n```\n\n```javascript\n// Conditional responses based on request\nconst tap = mock.taps.inject((request) =\u003e {\n  // Return error for URLs containing 'error'\n  if (request.url.includes('error')) {\n    return {\n      response: { error: \"Something went wrong\" },\n      statusCode: 500\n    };\n  }\n\n  // Return success for everything else\n  return {\n    response: { status: \"success\" },\n    statusCode: 200\n  };\n});\n```\n\n```javascript\n// Dynamic headers based on request\nconst tap = mock.taps.inject(\n  (request) =\u003e ({\n    response: \"OK\",\n    statusCode: 200,\n    headers: {\n      \"X-Original-Method\": request.method,\n      \"X-Original-URL\": request.url,\n      \"X-Original-Host\": request.hostname\n    }\n  }),\n  { url: \"/api/mirror\" }\n);\n```\n\n# Rate Limiting\n\nMockHttp supports rate limiting using [@fastify/rate-limit](https://github.com/fastify/fastify-rate-limit). Rate limiting is **enabled by default** at **1000 requests per minute** with **localhost (127.0.0.1 and ::1) excluded** from rate limiting.\n\n## Default Rate Limiting\n\nBy default, MockHttp applies the following rate limit:\n- **1000 requests per minute** per IP address\n- **Localhost is excluded** - requests from 127.0.0.1 and ::1 bypass rate limiting (ideal for local development and testing)\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\n\nconst mock = new MockHttp();\nawait mock.start();\n// Rate limiting is active (1000 req/min) except for localhost\n```\n\n## Customizing Rate Limiting\n\nTo customize rate limiting, pass a `rateLimit` configuration object when creating your MockHttp instance:\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\n\nconst mock = new MockHttp({\n  rateLimit: {\n    max: 100,              // Maximum 100 requests\n    timeWindow: '1 minute' // Per 1 minute window\n  }\n});\n\nawait mock.start();\n```\n\n## Common Configuration Options\n\nThe `rateLimit` option accepts all [@fastify/rate-limit options](https://github.com/fastify/fastify-rate-limit#options):\n\n### Basic Rate Limiting\n\n```javascript\n// Limit to 50 requests per minute\nconst mock = new MockHttp({\n  rateLimit: {\n    max: 50,\n    timeWindow: '1 minute'\n  }\n});\n```\n\n### Stricter Limits with Custom Error Response\n\n```javascript\nconst mock = new MockHttp({\n  rateLimit: {\n    max: 30,\n    timeWindow: 60000, // 1 minute in milliseconds\n    errorResponseBuilder: (req, context) =\u003e ({\n      statusCode: 429,\n      error: 'Too Many Requests',\n      message: `Rate limit exceeded. Try again in ${context.after}`\n    })\n  }\n});\n```\n\n### Allow List (Exclude Specific IPs)\n\n```javascript\nconst mock = new MockHttp({\n  rateLimit: {\n    max: 100,\n    timeWindow: '1 minute',\n    allowList: ['127.0.0.1', '192.168.1.100'] // These IPs bypass rate limiting\n  }\n});\n```\n\n### Custom Key Generator (Rate Limit by Header)\n\n```javascript\nconst mock = new MockHttp({\n  rateLimit: {\n    max: 100,\n    timeWindow: '1 minute',\n    keyGenerator: (request) =\u003e {\n      // Rate limit by API key instead of IP\n      return request.headers['x-api-key'] || request.ip;\n    }\n  }\n});\n```\n\n### Advanced Configuration\n\n```javascript\nconst mock = new MockHttp({\n  rateLimit: {\n    global: true,                    // Apply to all routes\n    max: 100,                        // Max requests\n    timeWindow: '1 minute',          // Time window\n    cache: 10000,                    // Cache size for tracking clients\n    skipOnError: false,              // Don't skip on storage errors\n    ban: 10,                         // Ban after 10 rate limit violations\n    continueExceeding: false,        // Don't reset window on each request\n    enableDraftSpec: true,           // Use IETF draft spec headers\n    addHeaders: {                    // Customize rate limit headers\n      'x-ratelimit-limit': true,\n      'x-ratelimit-remaining': true,\n      'x-ratelimit-reset': true\n    }\n  }\n});\n```\n\n## Disabling Rate Limiting\n\nTo disable rate limiting completely, set the `rateLimit` option to `false`:\n\n```javascript\nconst mock = new MockHttp({\n  rateLimit: false // Completely disable rate limiting\n});\n\nawait mock.start();\n// No rate limiting is applied to any requests\n```\n\n**Note:** To change rate limiting settings after the server has started, you must restart the server:\n\n```javascript\nconst mock = new MockHttp();\nawait mock.start(); // Starts with default rate limiting\n\n// To change or disable rate limiting:\nawait mock.close();\nmock.rateLimit = undefined; // or set new options\nawait mock.start(); // Restarts with new settings\n```\n\n## Available Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `max` | number \\| function | `1000` | Maximum requests per time window |\n| `timeWindow` | number \\| string | `60000` | Duration of rate limit window (milliseconds or string like '1 minute') |\n| `cache` | number | `5000` | LRU cache size for tracking clients |\n| `allowList` | array \\| function | `[]` | IPs or function to exclude from rate limiting |\n| `keyGenerator` | function | IP-based | Function to generate unique client identifier |\n| `errorResponseBuilder` | function | Default 429 | Custom error response function |\n| `skipOnError` | boolean | `false` | Skip rate limiting if storage errors occur |\n| `ban` | number | `-1` | Ban client after N violations (disabled by default) |\n| `continueExceeding` | boolean | `false` | Renew time window on each request while limited |\n| `enableDraftSpec` | boolean | `false` | Use IETF draft specification headers |\n\nFor the complete list of options, see the [@fastify/rate-limit documentation](https://github.com/fastify/fastify-rate-limit#options).\n\n# Logging\n\nMockHttp uses [Pino](https://github.com/pinojs/pino) for logging via Fastify's built-in logger. Logging is **enabled by default** but can be disabled when needed.\n\n## Disabling Logging\n\n```javascript\nimport { MockHttp } from '@jaredwray/mockhttp';\n\nconst mock = new MockHttp({ logging: false });\nawait mock.start();\n// Server runs silently without any log output\n```\n\nYou can also disable logging via the `LOGGING` environment variable:\n\n```bash\nLOGGING=false node your-app.js\n```\n\n# Flexible URL Matching\n\nMockHttp ignores trailing path segments that come after the parsable portion of a URL. This is useful when a client appends extra data to a known endpoint — instead of returning 404, MockHttp serves the closest matching route.\n\nFor example, all of these are served by `/status/:code`:\n\n```\nGET /status/429\nGET /status/429/\nGET /status/429/foo\nGET /status/429/foo/bar\n```\n\nThe rewrite preserves the query string and only triggers when a more specific route exists; URLs whose first path segment doesn't correspond to a registered route still return 404.\n\n# API Reference\n\n## MockHttp Class\n\n### Constructor\n\n```javascript\nnew MockHttp(options?)\n```\n\n**Parameters:**\n- `options?` (MockHttpOptions):\n  - `port?`: number - The port to listen on (default: 3000)\n  - `host?`: string - The host to listen on (default: '0.0.0.0')\n  - `autoDetectPort?`: boolean - Auto-detect next available port if in use (default: true)\n  - `helmet?`: boolean - Use Helmet for security headers (default: true)\n  - `apiDocs?`: boolean - Enable Swagger API documentation (default: true)\n  - `rateLimit?`: RateLimitPluginOptions - Configure rate limiting (default: 1000 req/min, localhost excluded)\n  - `logging?`: boolean - Enable logging (default: true)\n  - `httpBin?`: HttpBinOptions - Configure which httpbin routes to enable\n    - `httpMethods?`: boolean - Enable HTTP method routes (default: true)\n    - `redirects?`: boolean - Enable redirect routes (default: true)\n    - `requestInspection?`: boolean - Enable request inspection routes (default: true)\n    - `responseInspection?`: boolean - Enable response inspection routes (default: true)\n    - `statusCodes?`: boolean - Enable status code routes (default: true)\n    - `responseFormats?`: boolean - Enable response format routes (default: true)\n    - `cookies?`: boolean - Enable cookie routes (default: true)\n    - `anything?`: boolean - Enable anything routes (default: true)\n    - `auth?`: boolean - Enable authentication routes (default: true)\n    - `images?`: boolean - Enable image routes (default: true)\n  - `https?`: boolean | HttpsOptions - Enable HTTPS with auto-generated or custom certificates (default: undefined/disabled)\n  - `http2?`: boolean - Enable HTTP/2 support (default: false)\n  - `http1?`: boolean - Allow HTTP/1.1 fallback when using HTTP/2 with HTTPS (default: true)\n  - `hookOptions?`: HookifiedOptions - Hookified options\n\n### Properties\n\n- `port`: number - Get/set the server port\n- `host`: string - Get/set the server host\n- `autoDetectPort`: boolean - Get/set auto-detect port behavior\n- `helmet`: boolean - Get/set Helmet security headers\n- `apiDocs`: boolean - Get/set API documentation\n- `logging`: boolean - Get/set logging enabled state\n- `rateLimit`: RateLimitPluginOptions | undefined - Get/set rate limiting options\n- `httpBin`: HttpBinOptions - Get/set httpbin route options\n- `https`: HttpsOptions | undefined - Get/set HTTPS configuration\n- `isHttps`: boolean - Whether the server is running with HTTPS\n- `http2`: boolean - Get/set HTTP/2 support\n- `http1`: boolean - Get/set HTTP/1.1 fallback for HTTP/2 with HTTPS\n- `server`: FastifyInstance - Get/set the Fastify server instance\n- `taps`: TapManager - Get/set the TapManager instance\n\n### Methods\n\n#### `async start()`\n\nStart the Fastify server. If already running, it will be closed and restarted.\n\n#### `async close()`\n\nStop the Fastify server.\n\n#### `async detectPort()`\n\nDetect the next available port.\n\n**Returns:** number - The available port\n\n#### `async registerApiDocs(fastifyInstance?)`\n\nRegister Swagger API documentation routes.\n\n#### `async registerHttpMethods(fastifyInstance?)`\n\nRegister HTTP method routes (GET, POST, PUT, PATCH, DELETE).\n\n#### `async registerStatusCodeRoutes(fastifyInstance?)`\n\nRegister status code routes.\n\n#### `async registerRequestInspectionRoutes(fastifyInstance?)`\n\nRegister request inspection routes (headers, ip, user-agent).\n\n#### `async registerResponseInspectionRoutes(fastifyInstance?)`\n\nRegister response inspection routes (cache, etag, response-headers).\n\n#### `async registerResponseFormatRoutes(fastifyInstance?)`\n\nRegister response format routes (json, xml, html, etc.).\n\n#### `async registerRedirectRoutes(fastifyInstance?)`\n\nRegister redirect routes (absolute, relative, redirect-to).\n\n#### `async registerCookieRoutes(fastifyInstance?)`\n\nRegister cookie routes (get, set, delete).\n\n#### `async registerAnythingRoutes(fastifyInstance?)`\n\nRegister \"anything\" catch-all routes.\n\n#### `async registerAuthRoutes(fastifyInstance?)`\n\nRegister authentication routes (basic, bearer, digest, hidden-basic).\n\n#### `async registerImageRoutes(fastifyInstance?)`\n\nRegister image routes (jpeg, png, svg, webp) with content negotiation support.\n\n## Taps (Response Injection)\n\nAccess the TapManager via `mockHttp.taps` to inject custom responses.\n\n### `taps.inject(response, matcher?)`\n\nInjects a custom response for requests matching the criteria.\n\n**Parameters:**\n- `response` (InjectionResponse | InjectionResponseFunction):\n  - **Static Response** (InjectionResponse):\n    - `response`: string | object | Buffer - The response body\n    - `statusCode?`: number - HTTP status code (default: 200)\n    - `headers?`: object - Response headers\n  - **Function Response** (InjectionResponseFunction):\n    - A function that receives the Fastify request object and returns an InjectionResponse\n    - `(request: FastifyRequest) =\u003e InjectionResponse`\n    - Allows dynamic response generation based on request properties (url, method, headers, etc.)\n\n- `matcher?` (InjectionMatcher) - Optional matching criteria:\n  - `url?`: string - URL path (supports wildcards with `*`)\n  - `method?`: string - HTTP method (GET, POST, etc.)\n  - `hostname?`: string - Hostname to match\n  - `headers?`: object - Headers that must be present\n\n**Returns:** `InjectionTap` - A tap object with a unique `id` that can be used to remove the injection\n\n## `taps.removeInjection(tapOrId)`\n\nRemoves an injection.\n\n**Parameters:**\n- `tapOrId`: InjectionTap | string - The tap object or tap ID to remove\n\n**Returns:** boolean - `true` if removed, `false` if not found\n\n### `taps.injections`\n\nA getter that returns a Map of all active injection taps.\n\n**Returns:** `Map\u003cstring, InjectionTap\u003e` - Map of all active injections with tap IDs as keys\n\n## `taps.clear()`\n\nRemoves all injections.\n\n## `taps.hasInjections`\n\nA getter that returns whether there are any active injections.\n\n**Returns:** boolean - `true` if there are active injections, `false` otherwise\n\n# About mockhttp.org \n\n[mockhttp.org](https://mockhttp.org) is a free service that runs this codebase and allows you to use it for testing purposes. It is a simple way to mock HTTP responses for testing purposes. It is globally available has some limitations on it to prevent abuse such as requests per second. It is ran via [Cloudflare](https://cloudflare.com) and [Google Cloud Run](https://cloud.google.com/run/) across 7 regions globally and can do millions of requests per second.\n\n# Contributing\n\nPlease read our [CODE OF CONDUCT](CODE_OF_CONDUCT.md) and [CONTRIBUTING](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n# License\n\n[MIT License \u0026 © Jared Wray](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Fmockhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredwray%2Fmockhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredwray%2Fmockhttp/lists"}