{"owner":"stoplightio","repo":"prism","hasSkills":true,"totalSkillsCount":5,"totalTokensCount":4714,"categories":["claude-rule","plugin-manifest"],"hasMcp":false,"mcpConfig":null,"found":["CLAUDE.md","packages/cli/README.md","packages/core/README.md","packages/http-server/README.md","packages/http/README.md"],"skills":{"CLAUDE.md":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Overview\n\nPrism is an open-source API mocking and contract testing platform supporting OpenAPI v2/v3.0/v3.1 and Postman Collections. It provides a mock server and validation proxy.\n\n## Common Commands\n\n```bash\n# Install dependencies\nnpm ci\n\n# Build (clean + compile TypeScript)\nnpm run build\n\n# Run all tests\nnpm test\n\n# Run tests for a specific package or file\nnpm test -- --testPathPattern=\"core\"\nnpm test -- packages/http/src/__tests__/client.spec.ts\n\n# Lint\nnpm run lint\nnpm run lint.fix\n\n# Run CLI directly during development (from packages/cli)\ncd packages/cli && npm run cli -- mock openapi.yaml\n\n# Debug CLI (attaches Node inspector)\ncd packages/cli && npm run cli:debug -- mock file.oas.yml\n\n# Build binary\nnpm run build.binary\n\n# Integration/harness tests (requires build.binary first)\nnpm run test.harness\n```\n\n## Architecture\n\nThis is a **Lerna monorepo** with npm workspaces. Packages have a strict layering:\n\n```\npackages/\n├── core/         # Base abstractions: routing, validation, mocking contracts\n├── http/         # HTTP-specific: mocker, validator, forwarder, router, negotiator\n├── http-server/  # HTTP server using Micri; wires http/ into a running server\n└── cli/          # CLI entry point using Yargs; commands: mock, proxy\n```\n\n**Data flow**: CLI → HTTP-Server → HTTP (mocker/validator/forwarder/router) → Core\n\n### Key Design Patterns\n\n- **fp-ts throughout**: The codebase uses `Either`, `TaskEither`, `Reader`, and `Option` from fp-ts for error handling and dependency injection. Expect functional-style pipelines via `pipe()`.\n- **IPrismConfig / IHttpConfig**: Central config objects passed as dependencies control behavior (dynamic mocking, validation strictness, proxy mode).\n- **Pino structured logging**: A logger instance is passed as a context through nearly all operations.\n- **Mocker pipeline** (`packages/http/src/mocker/`): Negotiates content type → selects example or generates with `json-schema-faker` → applies callbacks.\n- **Validator pipeline** (`packages/http/src/validator/`): AJV-based validation for request/response bodies, headers, path/query params.\n\n### Important Files\n\n| File                                   | Purpose                                        |\n| -------------------------------------- | ---------------------------------------------- |\n| `packages/core/src/factory.ts`         | Creates Prism instances                        |\n| `packages/http/src/client.ts`          | HTTP client factory                            |\n| `packages/http/src/mocker/index.ts`    | Mock response generation entrypoint            |\n| `packages/http/src/validator/index.ts` | Validation entrypoint                          |\n| `packages/http/src/router/index.ts`    | Matches requests to OpenAPI operations         |\n| `packages/http/src/forwarder/index.ts` | Upstream proxy forwarding                      |\n| `packages/cli/src/commands/`           | `mock` and `proxy` CLI command implementations |\n| `packages/http-server/src/index.ts`    | HTTP server setup                              |\n\n## Testing\n\n- Tests live in `__tests__/` directories alongside source files, named `*.spec.ts` or `*.test.ts`\n- Jest projects are scoped per package: `HTTP-SERVER`, `HTTP`, `CORE`, `CLI`\n- `nock` is used for HTTP mocking in tests\n- Harness tests (`packages/cli/src/__tests__/harness/`) test the compiled binary end-to-end\n\n## Code Style\n\n- Prettier: 120-char line width, single quotes, trailing commas (es5)\n- ESLint with `@typescript-eslint` — `lint-staged` auto-fixes on commit via Husky\n- Arrow functions: omit parens for single parameter\n- TypeScript strict mode; `ttypescript` (ttsc) is used for compilation with custom transformers\n\n## Branch & Release\n\n- Feature branches: `feature/*`, `chore/*`, `fix/*`\n- Releases managed via Lerna (`npm run release`)\n- Node.js minimum: 18.20.1\n","packages/cli/README.md":"# prism-cli\n\nYou can install the command line CLI using `npm i -g @stoplight/prism-cli`\n\nTo get an overview of all the commands, just do `prism help`\n\n## Documentation\n\nRead me about the [Prism CLI](../../docs/getting-started/03-cli.md).\n\n## Development\n\n### Debugging\n\n1. `npm run cli:debug -- mock file.oas.yml`\n2. Run your preferred debugger on the newly created process. If you're into VS Code, you can create `.vscode/launch.json` and put this content inside:\n\n```json\n{\n  \"type\": \"node\",\n  \"request\": \"attach\",\n  \"name\": \"Attach\",\n  \"port\": 9229\n},\n```\n\n4. Enjoy the breakpoints :)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5a343b5d-430b-4fea-8299-845b23c0b407&page=README.md\" />\n","packages/core/README.md":"# Prism Core\n\nThis package contains base abstract interfaces. Generally, you do not want to look at this repository, as there's nothing more than philosophycal reasonments that aren't exactly that pragmatic.\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=d703ffa4-a736-40cc-a994-9116c1e7e4d8&page=README.md\" />\n","packages/http-server/README.md":"# Prism Server\n\n**NOTE:** The current API is still experimental and could change with no notice. Use at your own risk.\n\nUsage:\n\n```javascript\nconst { createServer } = require('@stoplight/prism-http-server');\nconst { getHttpOperationsFromSpec } = require('@stoplight/prism-cli/dist/operations');\nconst { createLogger } = require('@stoplight/prism-core');\n\nasync function createPrismServer() {\n  const operations = await getHttpOperationsFromSpec('YOUR-URL');\n\n  const server = createServer(operations, {\n    components: {\n      logger: createLogger('TestLogger'),\n    },\n    cors: true,\n    config: {\n      checkSecurity: true,\n      validateRequest: true,\n      validateResponse: true,\n      mock: { dynamic: false },\n      isProxy: false,\n      errors: false,\n    },\n  });\n  await server.listen(4010);\n\n  return {\n    close: server.close.bind(server),\n  };\n}\n\nconst server = await createPrismServer();\n\nserver.close();\n```\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=6cab5318-35c8-4dff-b6de-7007ba44442c&page=README.md\" />\n","packages/http/README.md":"# HTTP Client\n\nThis package provides a HTTP client featuring the ability to:\n\n- mock responses based of OpenAPI spec\n- make requests to a HTTP server\n- validate the request and/or the response according to the provided OpenAPI Specification file\n\nIn essence it's an HTTP client with the ability to mock responses and validate requests.\n\nThe goal of this document is to provide you with some basic code examples to get you started and to cover some of the advanced scenarios.\n\n## Important\n\nIf you're a regular user and not a PRO, you might to want to use the [User facing client](../../docs/guides/07-http-client.md) which provides a better an higher lever API\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Basic Usages](#basic-usages)\n  - [Mock All Responses](#mock-all-responses)\n  - [Mock Single Response](#mock-single-response)\n  - [Make Request To An Upstream Server](#make-request-to-an-upstream-server)\n- [Advanced Topics](#advanced-topics)\n  - [Creating Prism Instance](#creating-prism-instance)\n    - [Config Object](#config-object)\n      - [Config Examples](#config-examples)\n  - [Loading specs](#loading-specs)\n  - [Making requests](#making-requests)\n    - [Server Validation](#server-validation)\n  - [Understanding response](#understanding-response)\n  - [Prism Decision Flow Diagram](#prism-decision-flow-diagram)\n- [Anonymized analytics](#anonymized-analytics)\n\n# Installation\n\n```bash\nnpm install @stoplight/prism-http\n```\n\n# Basic Usages\n\n> Note: the examples in this document use the following spec\n\n```yaml\nopenapi: 3.0.2\npaths:\n  /todos:\n    get:\n      parameters:\n        - name: title\n          in: query\n          style: form\n          schema:\n            enum:\n              - eat\n              - drink\n      responses:\n        200:\n          description: Get Todo Items\n          content:\n            'text/plain':\n              example: Write great OpenAPI specs!\n```\n\n## Mock All Responses\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it as a mocker generating static examples\nconst prism = Prism.createInstance({\n  mock: { dynamic: false },\n  validate: { request: { query: true } },\n});\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/todos',\n    },\n    headers: {\n      Accept: 'text/plain',\n    },\n  },\n  operations\n);\n```\n\nOutput\n\n```bash\n{\n  statusCode: 200,\n  headers: { 'Content-type': 'text/plain' },\n  body: 'Write great OpenAPI specs!'\n}\n```\n\nNote: the `request` method returns a [`TaskEither` monad](https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html). So in case you want to extract the result, you're going to need to use the [pipe](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) function.\n\n```ts\nreturn pipe(\n  prism.request(\n    {\n      method: 'get',\n      url: {\n        path: '/todos',\n      },\n      headers: {\n        Accept: 'text/plain',\n      },\n    },\n    operations\n  ),\n  TE.fold(console.error, console.log)\n)(); // returns a Promise\n```\n\n## Mock Single Response\n\nIn the following example we will first instantiate Prism to make requests to an actual server.\n\nLater we alter than behaviour by passing a config object to the `request` function.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Note that by default we don't want to mock responses\nconst prism = Prism.createInstance({ mock: { dynamic: false } });\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  {\n    // We can override the default behaviour per request.\n    mock: {\n      dynamic: true,\n    },\n  },\n  operations\n);\n```\n\n## Make Request To An Upstream Server\n\nWe don't want to mock a reqeust, we simply want to make the request, hit the actual server and get the response back.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make HTTP requests (mock: {dynamic: false})\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\n\nreturn prism.request({\n  method: 'get',\n  url: {\n    path: '/facts',\n    baseUrl: 'https://cat-fact.herokuapp.com',\n  },\n});\n```\n\nIn response you'll get some... facts about cats. For example:\n\n> Cats aren’t the only animals that purr — squirrels, lemurs, elephants, and even gorillas purr too.\n\n:)\n\n# Advanced Topics\n\n## Creating Prism Instance\n\nIn order to create and instance of HTTP Client (later referred to as `prism` for simplicity) use the `createInstance` function, like so:\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config /*, components */);\n```\n\nThere are two (both optional) arguments you can supply `createInstance` with:\n\n- config (of `IHttpConfig` type)\n- components (of `PrismHttpComponents` type)\n\nWe will cover the `config` argument in next section and we'll leave `components` for some other time (overriding default `components` is the _ultimate advanced stuff_).\n\n### Config Object\n\nPrism's config object (`IHttpConfig`) allows you to manipulate Prism's behaviour in many ways. For instance:\n\n- turn validation on and off\n- influence Prism's mocked response generation strategy\n\nThe actual interface looks like this (but rather than explain each property we're going to look at some examples)\n\n```ts\nexport interface IHttpConfig extends IPrismConfig {\n  mock: { dynamic: false } | IHttpOperationConfig;\n  validateRequest: boolean;\n  validateResponse: boolean;\n  checkSecurity: boolean;\n  errors: boolean;\n}\n```\n\n#### Config Examples\n\n**When mocking a response generate static response**\n\n```javascript\nconst config = {\n  mock: {\n    dynamic: false,\n  },\n};\n```\n\nGenerating static responses means that if an OpenAPI operation's response has any examples defined the payload we construct will use those examples.\n\nThis contrasts \"dynamic responses\" which means generating responses from a json schema.\n\n**Return named example of a specified key**\n\n```javascript\nconst config = {\n  mock: {\n    exampleKey: 'key',\n  },\n};\n```\n\nIn OpenAPI Specification 3 one can construct such response that will have multiple examples mapped by keys.\nThis configuration allows you to be very specific which example you want to choose.\n\n**Return 403 response of specified mime type**\n\n```javascript\nconst config = {\n  mock: {\n    code: 403,\n    mediaTypes: ['application/xml'],\n  },\n};\n```\n\nThis will enforce a 403 response (given that such response is defined in your OpenAPI file).\n\n## Loading specs\n\nThe Http package does not have any pre-canned loader for the specification files. You need to feed it with an array of operations that can be used for the request/response cycle.\n\nYou can find an example by looking at the [operations.ts](../cli/src/operations.ts) file in the CLI package.\n\n## Making requests\n\nTo make a basic request you need to do the following\n\n```javascript\nconst request = {\n  method: 'get',\n  url: {\n    path: '/path', // must be prefixed with slash\n  },\n};\nconst promise = prism.request(request, operations);\n```\n\nThe request object has the following interface\n\n```ts\nexport interface IHttpRequest {\n  method: HttpMethod;\n  url: IHttpUrl;\n  headers?: IHttpNameValue;\n  body?: unknown;\n}\n```\n\nAll of this is pretty standard except the `url.baseUrl` which we will describe in more details.\n\n### Server Validation\n\nConsider a request\n\n```javascript\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts', // must be prefixed with slash\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nNotice that `baseUrl` is defined.\n\nThis will instruct Prism to do one of the two:\n\n- if mocking is **disabled** (`{ mock: {dynamic: false} }`)\n  - it will use that `baseUrl` to make a request to the server (`GET https://cat-fact.herokuapp.com/facts`)\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **add an input warning to the .request return value if it is not valid**\n- if mocking is **enabled**\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **return an error if it is not valid**\n\n## Understanding response\n\nThe `prism.request` resolved (it's a Promise!) value consists of:\n\n- input - copy of the request object you provided\n- output - the HTTP response\n- validations\n  - input - list of warnings/errors related to you http request object\n  - output - list of warnings/errors related to you http response object\n\nValidations are still subject of tests and experimentation therefore we will not cover them fully for the time being.\n\nOne example however is that for a given example\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make http requests\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nYou would get this in response\n\n```bash\n[\n  {\n    message: 'Route not resolved, no resource provided.',\n    source: 'https://stoplight.io/prism/errors#NO_RESOURCE_PROVIDED_ERROR',\n    code: 404,\n    severity: 1\n  }\n]\n```\n\n## Prism Decision Flow Diagram\n\nThe below diagram represents all logical decision we make to figure out the best HTTP response to the specific request.\n\n![Decision Flow Diagram](./docs/images/mock-server-dfd.jpeg)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=872f5d30-d243-4e27-9afc-e21416a841be&page=README.md\" />\n"},"files":{"CLAUDE.md":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Overview\n\nPrism is an open-source API mocking and contract testing platform supporting OpenAPI v2/v3.0/v3.1 and Postman Collections. It provides a mock server and validation proxy.\n\n## Common Commands\n\n```bash\n# Install dependencies\nnpm ci\n\n# Build (clean + compile TypeScript)\nnpm run build\n\n# Run all tests\nnpm test\n\n# Run tests for a specific package or file\nnpm test -- --testPathPattern=\"core\"\nnpm test -- packages/http/src/__tests__/client.spec.ts\n\n# Lint\nnpm run lint\nnpm run lint.fix\n\n# Run CLI directly during development (from packages/cli)\ncd packages/cli && npm run cli -- mock openapi.yaml\n\n# Debug CLI (attaches Node inspector)\ncd packages/cli && npm run cli:debug -- mock file.oas.yml\n\n# Build binary\nnpm run build.binary\n\n# Integration/harness tests (requires build.binary first)\nnpm run test.harness\n```\n\n## Architecture\n\nThis is a **Lerna monorepo** with npm workspaces. Packages have a strict layering:\n\n```\npackages/\n├── core/         # Base abstractions: routing, validation, mocking contracts\n├── http/         # HTTP-specific: mocker, validator, forwarder, router, negotiator\n├── http-server/  # HTTP server using Micri; wires http/ into a running server\n└── cli/          # CLI entry point using Yargs; commands: mock, proxy\n```\n\n**Data flow**: CLI → HTTP-Server → HTTP (mocker/validator/forwarder/router) → Core\n\n### Key Design Patterns\n\n- **fp-ts throughout**: The codebase uses `Either`, `TaskEither`, `Reader`, and `Option` from fp-ts for error handling and dependency injection. Expect functional-style pipelines via `pipe()`.\n- **IPrismConfig / IHttpConfig**: Central config objects passed as dependencies control behavior (dynamic mocking, validation strictness, proxy mode).\n- **Pino structured logging**: A logger instance is passed as a context through nearly all operations.\n- **Mocker pipeline** (`packages/http/src/mocker/`): Negotiates content type → selects example or generates with `json-schema-faker` → applies callbacks.\n- **Validator pipeline** (`packages/http/src/validator/`): AJV-based validation for request/response bodies, headers, path/query params.\n\n### Important Files\n\n| File                                   | Purpose                                        |\n| -------------------------------------- | ---------------------------------------------- |\n| `packages/core/src/factory.ts`         | Creates Prism instances                        |\n| `packages/http/src/client.ts`          | HTTP client factory                            |\n| `packages/http/src/mocker/index.ts`    | Mock response generation entrypoint            |\n| `packages/http/src/validator/index.ts` | Validation entrypoint                          |\n| `packages/http/src/router/index.ts`    | Matches requests to OpenAPI operations         |\n| `packages/http/src/forwarder/index.ts` | Upstream proxy forwarding                      |\n| `packages/cli/src/commands/`           | `mock` and `proxy` CLI command implementations |\n| `packages/http-server/src/index.ts`    | HTTP server setup                              |\n\n## Testing\n\n- Tests live in `__tests__/` directories alongside source files, named `*.spec.ts` or `*.test.ts`\n- Jest projects are scoped per package: `HTTP-SERVER`, `HTTP`, `CORE`, `CLI`\n- `nock` is used for HTTP mocking in tests\n- Harness tests (`packages/cli/src/__tests__/harness/`) test the compiled binary end-to-end\n\n## Code Style\n\n- Prettier: 120-char line width, single quotes, trailing commas (es5)\n- ESLint with `@typescript-eslint` — `lint-staged` auto-fixes on commit via Husky\n- Arrow functions: omit parens for single parameter\n- TypeScript strict mode; `ttypescript` (ttsc) is used for compilation with custom transformers\n\n## Branch & Release\n\n- Feature branches: `feature/*`, `chore/*`, `fix/*`\n- Releases managed via Lerna (`npm run release`)\n- Node.js minimum: 18.20.1\n","packages/cli/README.md":"# prism-cli\n\nYou can install the command line CLI using `npm i -g @stoplight/prism-cli`\n\nTo get an overview of all the commands, just do `prism help`\n\n## Documentation\n\nRead me about the [Prism CLI](../../docs/getting-started/03-cli.md).\n\n## Development\n\n### Debugging\n\n1. `npm run cli:debug -- mock file.oas.yml`\n2. Run your preferred debugger on the newly created process. If you're into VS Code, you can create `.vscode/launch.json` and put this content inside:\n\n```json\n{\n  \"type\": \"node\",\n  \"request\": \"attach\",\n  \"name\": \"Attach\",\n  \"port\": 9229\n},\n```\n\n4. Enjoy the breakpoints :)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5a343b5d-430b-4fea-8299-845b23c0b407&page=README.md\" />\n","packages/core/README.md":"# Prism Core\n\nThis package contains base abstract interfaces. Generally, you do not want to look at this repository, as there's nothing more than philosophycal reasonments that aren't exactly that pragmatic.\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=d703ffa4-a736-40cc-a994-9116c1e7e4d8&page=README.md\" />\n","packages/http-server/README.md":"# Prism Server\n\n**NOTE:** The current API is still experimental and could change with no notice. Use at your own risk.\n\nUsage:\n\n```javascript\nconst { createServer } = require('@stoplight/prism-http-server');\nconst { getHttpOperationsFromSpec } = require('@stoplight/prism-cli/dist/operations');\nconst { createLogger } = require('@stoplight/prism-core');\n\nasync function createPrismServer() {\n  const operations = await getHttpOperationsFromSpec('YOUR-URL');\n\n  const server = createServer(operations, {\n    components: {\n      logger: createLogger('TestLogger'),\n    },\n    cors: true,\n    config: {\n      checkSecurity: true,\n      validateRequest: true,\n      validateResponse: true,\n      mock: { dynamic: false },\n      isProxy: false,\n      errors: false,\n    },\n  });\n  await server.listen(4010);\n\n  return {\n    close: server.close.bind(server),\n  };\n}\n\nconst server = await createPrismServer();\n\nserver.close();\n```\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=6cab5318-35c8-4dff-b6de-7007ba44442c&page=README.md\" />\n","packages/http/README.md":"# HTTP Client\n\nThis package provides a HTTP client featuring the ability to:\n\n- mock responses based of OpenAPI spec\n- make requests to a HTTP server\n- validate the request and/or the response according to the provided OpenAPI Specification file\n\nIn essence it's an HTTP client with the ability to mock responses and validate requests.\n\nThe goal of this document is to provide you with some basic code examples to get you started and to cover some of the advanced scenarios.\n\n## Important\n\nIf you're a regular user and not a PRO, you might to want to use the [User facing client](../../docs/guides/07-http-client.md) which provides a better an higher lever API\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Basic Usages](#basic-usages)\n  - [Mock All Responses](#mock-all-responses)\n  - [Mock Single Response](#mock-single-response)\n  - [Make Request To An Upstream Server](#make-request-to-an-upstream-server)\n- [Advanced Topics](#advanced-topics)\n  - [Creating Prism Instance](#creating-prism-instance)\n    - [Config Object](#config-object)\n      - [Config Examples](#config-examples)\n  - [Loading specs](#loading-specs)\n  - [Making requests](#making-requests)\n    - [Server Validation](#server-validation)\n  - [Understanding response](#understanding-response)\n  - [Prism Decision Flow Diagram](#prism-decision-flow-diagram)\n- [Anonymized analytics](#anonymized-analytics)\n\n# Installation\n\n```bash\nnpm install @stoplight/prism-http\n```\n\n# Basic Usages\n\n> Note: the examples in this document use the following spec\n\n```yaml\nopenapi: 3.0.2\npaths:\n  /todos:\n    get:\n      parameters:\n        - name: title\n          in: query\n          style: form\n          schema:\n            enum:\n              - eat\n              - drink\n      responses:\n        200:\n          description: Get Todo Items\n          content:\n            'text/plain':\n              example: Write great OpenAPI specs!\n```\n\n## Mock All Responses\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it as a mocker generating static examples\nconst prism = Prism.createInstance({\n  mock: { dynamic: false },\n  validate: { request: { query: true } },\n});\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/todos',\n    },\n    headers: {\n      Accept: 'text/plain',\n    },\n  },\n  operations\n);\n```\n\nOutput\n\n```bash\n{\n  statusCode: 200,\n  headers: { 'Content-type': 'text/plain' },\n  body: 'Write great OpenAPI specs!'\n}\n```\n\nNote: the `request` method returns a [`TaskEither` monad](https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html). So in case you want to extract the result, you're going to need to use the [pipe](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) function.\n\n```ts\nreturn pipe(\n  prism.request(\n    {\n      method: 'get',\n      url: {\n        path: '/todos',\n      },\n      headers: {\n        Accept: 'text/plain',\n      },\n    },\n    operations\n  ),\n  TE.fold(console.error, console.log)\n)(); // returns a Promise\n```\n\n## Mock Single Response\n\nIn the following example we will first instantiate Prism to make requests to an actual server.\n\nLater we alter than behaviour by passing a config object to the `request` function.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Note that by default we don't want to mock responses\nconst prism = Prism.createInstance({ mock: { dynamic: false } });\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  {\n    // We can override the default behaviour per request.\n    mock: {\n      dynamic: true,\n    },\n  },\n  operations\n);\n```\n\n## Make Request To An Upstream Server\n\nWe don't want to mock a reqeust, we simply want to make the request, hit the actual server and get the response back.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make HTTP requests (mock: {dynamic: false})\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\n\nreturn prism.request({\n  method: 'get',\n  url: {\n    path: '/facts',\n    baseUrl: 'https://cat-fact.herokuapp.com',\n  },\n});\n```\n\nIn response you'll get some... facts about cats. For example:\n\n> Cats aren’t the only animals that purr — squirrels, lemurs, elephants, and even gorillas purr too.\n\n:)\n\n# Advanced Topics\n\n## Creating Prism Instance\n\nIn order to create and instance of HTTP Client (later referred to as `prism` for simplicity) use the `createInstance` function, like so:\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config /*, components */);\n```\n\nThere are two (both optional) arguments you can supply `createInstance` with:\n\n- config (of `IHttpConfig` type)\n- components (of `PrismHttpComponents` type)\n\nWe will cover the `config` argument in next section and we'll leave `components` for some other time (overriding default `components` is the _ultimate advanced stuff_).\n\n### Config Object\n\nPrism's config object (`IHttpConfig`) allows you to manipulate Prism's behaviour in many ways. For instance:\n\n- turn validation on and off\n- influence Prism's mocked response generation strategy\n\nThe actual interface looks like this (but rather than explain each property we're going to look at some examples)\n\n```ts\nexport interface IHttpConfig extends IPrismConfig {\n  mock: { dynamic: false } | IHttpOperationConfig;\n  validateRequest: boolean;\n  validateResponse: boolean;\n  checkSecurity: boolean;\n  errors: boolean;\n}\n```\n\n#### Config Examples\n\n**When mocking a response generate static response**\n\n```javascript\nconst config = {\n  mock: {\n    dynamic: false,\n  },\n};\n```\n\nGenerating static responses means that if an OpenAPI operation's response has any examples defined the payload we construct will use those examples.\n\nThis contrasts \"dynamic responses\" which means generating responses from a json schema.\n\n**Return named example of a specified key**\n\n```javascript\nconst config = {\n  mock: {\n    exampleKey: 'key',\n  },\n};\n```\n\nIn OpenAPI Specification 3 one can construct such response that will have multiple examples mapped by keys.\nThis configuration allows you to be very specific which example you want to choose.\n\n**Return 403 response of specified mime type**\n\n```javascript\nconst config = {\n  mock: {\n    code: 403,\n    mediaTypes: ['application/xml'],\n  },\n};\n```\n\nThis will enforce a 403 response (given that such response is defined in your OpenAPI file).\n\n## Loading specs\n\nThe Http package does not have any pre-canned loader for the specification files. You need to feed it with an array of operations that can be used for the request/response cycle.\n\nYou can find an example by looking at the [operations.ts](../cli/src/operations.ts) file in the CLI package.\n\n## Making requests\n\nTo make a basic request you need to do the following\n\n```javascript\nconst request = {\n  method: 'get',\n  url: {\n    path: '/path', // must be prefixed with slash\n  },\n};\nconst promise = prism.request(request, operations);\n```\n\nThe request object has the following interface\n\n```ts\nexport interface IHttpRequest {\n  method: HttpMethod;\n  url: IHttpUrl;\n  headers?: IHttpNameValue;\n  body?: unknown;\n}\n```\n\nAll of this is pretty standard except the `url.baseUrl` which we will describe in more details.\n\n### Server Validation\n\nConsider a request\n\n```javascript\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts', // must be prefixed with slash\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nNotice that `baseUrl` is defined.\n\nThis will instruct Prism to do one of the two:\n\n- if mocking is **disabled** (`{ mock: {dynamic: false} }`)\n  - it will use that `baseUrl` to make a request to the server (`GET https://cat-fact.herokuapp.com/facts`)\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **add an input warning to the .request return value if it is not valid**\n- if mocking is **enabled**\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **return an error if it is not valid**\n\n## Understanding response\n\nThe `prism.request` resolved (it's a Promise!) value consists of:\n\n- input - copy of the request object you provided\n- output - the HTTP response\n- validations\n  - input - list of warnings/errors related to you http request object\n  - output - list of warnings/errors related to you http response object\n\nValidations are still subject of tests and experimentation therefore we will not cover them fully for the time being.\n\nOne example however is that for a given example\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make http requests\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nYou would get this in response\n\n```bash\n[\n  {\n    message: 'Route not resolved, no resource provided.',\n    source: 'https://stoplight.io/prism/errors#NO_RESOURCE_PROVIDED_ERROR',\n    code: 404,\n    severity: 1\n  }\n]\n```\n\n## Prism Decision Flow Diagram\n\nThe below diagram represents all logical decision we make to figure out the best HTTP response to the specific request.\n\n![Decision Flow Diagram](./docs/images/mock-server-dfd.jpeg)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=872f5d30-d243-4e27-9afc-e21416a841be&page=README.md\" />\n"},"items":[{"name":"CLAUDE.md","path":"CLAUDE.md","rawUrl":"https://raw.githubusercontent.com/stoplightio/prism/HEAD/CLAUDE.md","title":"Claude Agent Guidelines & System Prompt","category":"claude-rule","format":"markdown","content":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Overview\n\nPrism is an open-source API mocking and contract testing platform supporting OpenAPI v2/v3.0/v3.1 and Postman Collections. It provides a mock server and validation proxy.\n\n## Common Commands\n\n```bash\n# Install dependencies\nnpm ci\n\n# Build (clean + compile TypeScript)\nnpm run build\n\n# Run all tests\nnpm test\n\n# Run tests for a specific package or file\nnpm test -- --testPathPattern=\"core\"\nnpm test -- packages/http/src/__tests__/client.spec.ts\n\n# Lint\nnpm run lint\nnpm run lint.fix\n\n# Run CLI directly during development (from packages/cli)\ncd packages/cli && npm run cli -- mock openapi.yaml\n\n# Debug CLI (attaches Node inspector)\ncd packages/cli && npm run cli:debug -- mock file.oas.yml\n\n# Build binary\nnpm run build.binary\n\n# Integration/harness tests (requires build.binary first)\nnpm run test.harness\n```\n\n## Architecture\n\nThis is a **Lerna monorepo** with npm workspaces. Packages have a strict layering:\n\n```\npackages/\n├── core/         # Base abstractions: routing, validation, mocking contracts\n├── http/         # HTTP-specific: mocker, validator, forwarder, router, negotiator\n├── http-server/  # HTTP server using Micri; wires http/ into a running server\n└── cli/          # CLI entry point using Yargs; commands: mock, proxy\n```\n\n**Data flow**: CLI → HTTP-Server → HTTP (mocker/validator/forwarder/router) → Core\n\n### Key Design Patterns\n\n- **fp-ts throughout**: The codebase uses `Either`, `TaskEither`, `Reader`, and `Option` from fp-ts for error handling and dependency injection. Expect functional-style pipelines via `pipe()`.\n- **IPrismConfig / IHttpConfig**: Central config objects passed as dependencies control behavior (dynamic mocking, validation strictness, proxy mode).\n- **Pino structured logging**: A logger instance is passed as a context through nearly all operations.\n- **Mocker pipeline** (`packages/http/src/mocker/`): Negotiates content type → selects example or generates with `json-schema-faker` → applies callbacks.\n- **Validator pipeline** (`packages/http/src/validator/`): AJV-based validation for request/response bodies, headers, path/query params.\n\n### Important Files\n\n| File                                   | Purpose                                        |\n| -------------------------------------- | ---------------------------------------------- |\n| `packages/core/src/factory.ts`         | Creates Prism instances                        |\n| `packages/http/src/client.ts`          | HTTP client factory                            |\n| `packages/http/src/mocker/index.ts`    | Mock response generation entrypoint            |\n| `packages/http/src/validator/index.ts` | Validation entrypoint                          |\n| `packages/http/src/router/index.ts`    | Matches requests to OpenAPI operations         |\n| `packages/http/src/forwarder/index.ts` | Upstream proxy forwarding                      |\n| `packages/cli/src/commands/`           | `mock` and `proxy` CLI command implementations |\n| `packages/http-server/src/index.ts`    | HTTP server setup                              |\n\n## Testing\n\n- Tests live in `__tests__/` directories alongside source files, named `*.spec.ts` or `*.test.ts`\n- Jest projects are scoped per package: `HTTP-SERVER`, `HTTP`, `CORE`, `CLI`\n- `nock` is used for HTTP mocking in tests\n- Harness tests (`packages/cli/src/__tests__/harness/`) test the compiled binary end-to-end\n\n## Code Style\n\n- Prettier: 120-char line width, single quotes, trailing commas (es5)\n- ESLint with `@typescript-eslint` — `lint-staged` auto-fixes on commit via Husky\n- Arrow functions: omit parens for single parameter\n- TypeScript strict mode; `ttypescript` (ttsc) is used for compilation with custom transformers\n\n## Branch & Release\n\n- Feature branches: `feature/*`, `chore/*`, `fix/*`\n- Releases managed via Lerna (`npm run release`)\n- Node.js minimum: 18.20.1\n","isInternal":false,"tokens":894,"sizeBytes":3988},{"name":"README.md","path":"packages/cli/README.md","rawUrl":"https://raw.githubusercontent.com/stoplightio/prism/HEAD/packages/cli/README.md","title":"cli Documentation","category":"plugin-manifest","format":"markdown","content":"# prism-cli\n\nYou can install the command line CLI using `npm i -g @stoplight/prism-cli`\n\nTo get an overview of all the commands, just do `prism help`\n\n## Documentation\n\nRead me about the [Prism CLI](../../docs/getting-started/03-cli.md).\n\n## Development\n\n### Debugging\n\n1. `npm run cli:debug -- mock file.oas.yml`\n2. Run your preferred debugger on the newly created process. If you're into VS Code, you can create `.vscode/launch.json` and put this content inside:\n\n```json\n{\n  \"type\": \"node\",\n  \"request\": \"attach\",\n  \"name\": \"Attach\",\n  \"port\": 9229\n},\n```\n\n4. Enjoy the breakpoints :)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5a343b5d-430b-4fea-8299-845b23c0b407&page=README.md\" />\n","isInternal":false,"tokens":454,"sizeBytes":1592},{"name":"README.md","path":"packages/core/README.md","rawUrl":"https://raw.githubusercontent.com/stoplightio/prism/HEAD/packages/core/README.md","title":"core Documentation","category":"plugin-manifest","format":"markdown","content":"# Prism Core\n\nThis package contains base abstract interfaces. Generally, you do not want to look at this repository, as there's nothing more than philosophycal reasonments that aren't exactly that pragmatic.\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=d703ffa4-a736-40cc-a994-9116c1e7e4d8&page=README.md\" />\n","isInternal":false,"tokens":331,"sizeBytes":1212},{"name":"README.md","path":"packages/http-server/README.md","rawUrl":"https://raw.githubusercontent.com/stoplightio/prism/HEAD/packages/http-server/README.md","title":"http-server Documentation","category":"plugin-manifest","format":"markdown","content":"# Prism Server\n\n**NOTE:** The current API is still experimental and could change with no notice. Use at your own risk.\n\nUsage:\n\n```javascript\nconst { createServer } = require('@stoplight/prism-http-server');\nconst { getHttpOperationsFromSpec } = require('@stoplight/prism-cli/dist/operations');\nconst { createLogger } = require('@stoplight/prism-core');\n\nasync function createPrismServer() {\n  const operations = await getHttpOperationsFromSpec('YOUR-URL');\n\n  const server = createServer(operations, {\n    components: {\n      logger: createLogger('TestLogger'),\n    },\n    cors: true,\n    config: {\n      checkSecurity: true,\n      validateRequest: true,\n      validateResponse: true,\n      mock: { dynamic: false },\n      isProxy: false,\n      errors: false,\n    },\n  });\n  await server.listen(4010);\n\n  return {\n    close: server.close.bind(server),\n  };\n}\n\nconst server = await createPrismServer();\n\nserver.close();\n```\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=6cab5318-35c8-4dff-b6de-7007ba44442c&page=README.md\" />\n","isInternal":false,"tokens":504,"sizeBytes":1928},{"name":"README.md","path":"packages/http/README.md","rawUrl":"https://raw.githubusercontent.com/stoplightio/prism/HEAD/packages/http/README.md","title":"http Documentation","category":"plugin-manifest","format":"markdown","content":"# HTTP Client\n\nThis package provides a HTTP client featuring the ability to:\n\n- mock responses based of OpenAPI spec\n- make requests to a HTTP server\n- validate the request and/or the response according to the provided OpenAPI Specification file\n\nIn essence it's an HTTP client with the ability to mock responses and validate requests.\n\nThe goal of this document is to provide you with some basic code examples to get you started and to cover some of the advanced scenarios.\n\n## Important\n\nIf you're a regular user and not a PRO, you might to want to use the [User facing client](../../docs/guides/07-http-client.md) which provides a better an higher lever API\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Basic Usages](#basic-usages)\n  - [Mock All Responses](#mock-all-responses)\n  - [Mock Single Response](#mock-single-response)\n  - [Make Request To An Upstream Server](#make-request-to-an-upstream-server)\n- [Advanced Topics](#advanced-topics)\n  - [Creating Prism Instance](#creating-prism-instance)\n    - [Config Object](#config-object)\n      - [Config Examples](#config-examples)\n  - [Loading specs](#loading-specs)\n  - [Making requests](#making-requests)\n    - [Server Validation](#server-validation)\n  - [Understanding response](#understanding-response)\n  - [Prism Decision Flow Diagram](#prism-decision-flow-diagram)\n- [Anonymized analytics](#anonymized-analytics)\n\n# Installation\n\n```bash\nnpm install @stoplight/prism-http\n```\n\n# Basic Usages\n\n> Note: the examples in this document use the following spec\n\n```yaml\nopenapi: 3.0.2\npaths:\n  /todos:\n    get:\n      parameters:\n        - name: title\n          in: query\n          style: form\n          schema:\n            enum:\n              - eat\n              - drink\n      responses:\n        200:\n          description: Get Todo Items\n          content:\n            'text/plain':\n              example: Write great OpenAPI specs!\n```\n\n## Mock All Responses\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it as a mocker generating static examples\nconst prism = Prism.createInstance({\n  mock: { dynamic: false },\n  validate: { request: { query: true } },\n});\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/todos',\n    },\n    headers: {\n      Accept: 'text/plain',\n    },\n  },\n  operations\n);\n```\n\nOutput\n\n```bash\n{\n  statusCode: 200,\n  headers: { 'Content-type': 'text/plain' },\n  body: 'Write great OpenAPI specs!'\n}\n```\n\nNote: the `request` method returns a [`TaskEither` monad](https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html). So in case you want to extract the result, you're going to need to use the [pipe](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) function.\n\n```ts\nreturn pipe(\n  prism.request(\n    {\n      method: 'get',\n      url: {\n        path: '/todos',\n      },\n      headers: {\n        Accept: 'text/plain',\n      },\n    },\n    operations\n  ),\n  TE.fold(console.error, console.log)\n)(); // returns a Promise\n```\n\n## Mock Single Response\n\nIn the following example we will first instantiate Prism to make requests to an actual server.\n\nLater we alter than behaviour by passing a config object to the `request` function.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Note that by default we don't want to mock responses\nconst prism = Prism.createInstance({ mock: { dynamic: false } });\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  {\n    // We can override the default behaviour per request.\n    mock: {\n      dynamic: true,\n    },\n  },\n  operations\n);\n```\n\n## Make Request To An Upstream Server\n\nWe don't want to mock a reqeust, we simply want to make the request, hit the actual server and get the response back.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make HTTP requests (mock: {dynamic: false})\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\n\nreturn prism.request({\n  method: 'get',\n  url: {\n    path: '/facts',\n    baseUrl: 'https://cat-fact.herokuapp.com',\n  },\n});\n```\n\nIn response you'll get some... facts about cats. For example:\n\n> Cats aren’t the only animals that purr — squirrels, lemurs, elephants, and even gorillas purr too.\n\n:)\n\n# Advanced Topics\n\n## Creating Prism Instance\n\nIn order to create and instance of HTTP Client (later referred to as `prism` for simplicity) use the `createInstance` function, like so:\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config /*, components */);\n```\n\nThere are two (both optional) arguments you can supply `createInstance` with:\n\n- config (of `IHttpConfig` type)\n- components (of `PrismHttpComponents` type)\n\nWe will cover the `config` argument in next section and we'll leave `components` for some other time (overriding default `components` is the _ultimate advanced stuff_).\n\n### Config Object\n\nPrism's config object (`IHttpConfig`) allows you to manipulate Prism's behaviour in many ways. For instance:\n\n- turn validation on and off\n- influence Prism's mocked response generation strategy\n\nThe actual interface looks like this (but rather than explain each property we're going to look at some examples)\n\n```ts\nexport interface IHttpConfig extends IPrismConfig {\n  mock: { dynamic: false } | IHttpOperationConfig;\n  validateRequest: boolean;\n  validateResponse: boolean;\n  checkSecurity: boolean;\n  errors: boolean;\n}\n```\n\n#### Config Examples\n\n**When mocking a response generate static response**\n\n```javascript\nconst config = {\n  mock: {\n    dynamic: false,\n  },\n};\n```\n\nGenerating static responses means that if an OpenAPI operation's response has any examples defined the payload we construct will use those examples.\n\nThis contrasts \"dynamic responses\" which means generating responses from a json schema.\n\n**Return named example of a specified key**\n\n```javascript\nconst config = {\n  mock: {\n    exampleKey: 'key',\n  },\n};\n```\n\nIn OpenAPI Specification 3 one can construct such response that will have multiple examples mapped by keys.\nThis configuration allows you to be very specific which example you want to choose.\n\n**Return 403 response of specified mime type**\n\n```javascript\nconst config = {\n  mock: {\n    code: 403,\n    mediaTypes: ['application/xml'],\n  },\n};\n```\n\nThis will enforce a 403 response (given that such response is defined in your OpenAPI file).\n\n## Loading specs\n\nThe Http package does not have any pre-canned loader for the specification files. You need to feed it with an array of operations that can be used for the request/response cycle.\n\nYou can find an example by looking at the [operations.ts](../cli/src/operations.ts) file in the CLI package.\n\n## Making requests\n\nTo make a basic request you need to do the following\n\n```javascript\nconst request = {\n  method: 'get',\n  url: {\n    path: '/path', // must be prefixed with slash\n  },\n};\nconst promise = prism.request(request, operations);\n```\n\nThe request object has the following interface\n\n```ts\nexport interface IHttpRequest {\n  method: HttpMethod;\n  url: IHttpUrl;\n  headers?: IHttpNameValue;\n  body?: unknown;\n}\n```\n\nAll of this is pretty standard except the `url.baseUrl` which we will describe in more details.\n\n### Server Validation\n\nConsider a request\n\n```javascript\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts', // must be prefixed with slash\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nNotice that `baseUrl` is defined.\n\nThis will instruct Prism to do one of the two:\n\n- if mocking is **disabled** (`{ mock: {dynamic: false} }`)\n  - it will use that `baseUrl` to make a request to the server (`GET https://cat-fact.herokuapp.com/facts`)\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **add an input warning to the .request return value if it is not valid**\n- if mocking is **enabled**\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **return an error if it is not valid**\n\n## Understanding response\n\nThe `prism.request` resolved (it's a Promise!) value consists of:\n\n- input - copy of the request object you provided\n- output - the HTTP response\n- validations\n  - input - list of warnings/errors related to you http request object\n  - output - list of warnings/errors related to you http response object\n\nValidations are still subject of tests and experimentation therefore we will not cover them fully for the time being.\n\nOne example however is that for a given example\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make http requests\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nYou would get this in response\n\n```bash\n[\n  {\n    message: 'Route not resolved, no resource provided.',\n    source: 'https://stoplight.io/prism/errors#NO_RESOURCE_PROVIDED_ERROR',\n    code: 404,\n    severity: 1\n  }\n]\n```\n\n## Prism Decision Flow Diagram\n\nThe below diagram represents all logical decision we make to figure out the best HTTP response to the specific request.\n\n![Decision Flow Diagram](./docs/images/mock-server-dfd.jpeg)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=872f5d30-d243-4e27-9afc-e21416a841be&page=README.md\" />\n","isInternal":false,"tokens":2531,"sizeBytes":10605}],"systemPromptSnippet":"<yakaai_skills repo=\"stoplightio/prism\">\n<!-- File: CLAUDE.md (Tokens: ~894 | Category: claude-rule) -->\n# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Overview\n\nPrism is an open-source API mocking and contract testing platform supporting OpenAPI v2/v3.0/v3.1 and Postman Collections. It provides a mock server and validation proxy.\n\n## Common Commands\n\n```bash\n# Install dependencies\nnpm ci\n\n# Build (clean + compile TypeScript)\nnpm run build\n\n# Run all tests\nnpm test\n\n# Run tests for a specific package or file\nnpm test -- --testPathPattern=\"core\"\nnpm test -- packages/http/src/__tests__/client.spec.ts\n\n# Lint\nnpm run lint\nnpm run lint.fix\n\n# Run CLI directly during development (from packages/cli)\ncd packages/cli && npm run cli -- mock openapi.yaml\n\n# Debug CLI (attaches Node inspector)\ncd packages/cli && npm run cli:debug -- mock file.oas.yml\n\n# Build binary\nnpm run build.binary\n\n# Integration/harness tests (requires build.binary first)\nnpm run test.harness\n```\n\n## Architecture\n\nThis is a **Lerna monorepo** with npm workspaces. Packages have a strict layering:\n\n```\npackages/\n├── core/         # Base abstractions: routing, validation, mocking contracts\n├── http/         # HTTP-specific: mocker, validator, forwarder, router, negotiator\n├── http-server/  # HTTP server using Micri; wires http/ into a running server\n└── cli/          # CLI entry point using Yargs; commands: mock, proxy\n```\n\n**Data flow**: CLI → HTTP-Server → HTTP (mocker/validator/forwarder/router) → Core\n\n### Key Design Patterns\n\n- **fp-ts throughout**: The codebase uses `Either`, `TaskEither`, `Reader`, and `Option` from fp-ts for error handling and dependency injection. Expect functional-style pipelines via `pipe()`.\n- **IPrismConfig / IHttpConfig**: Central config objects passed as dependencies control behavior (dynamic mocking, validation strictness, proxy mode).\n- **Pino structured logging**: A logger instance is passed as a context through nearly all operations.\n- **Mocker pipeline** (`packages/http/src/mocker/`): Negotiates content type → selects example or generates with `json-schema-faker` → applies callbacks.\n- **Validator pipeline** (`packages/http/src/validator/`): AJV-based validation for request/response bodies, headers, path/query params.\n\n### Important Files\n\n| File                                   | Purpose                                        |\n| -------------------------------------- | ---------------------------------------------- |\n| `packages/core/src/factory.ts`         | Creates Prism instances                        |\n| `packages/http/src/client.ts`          | HTTP client factory                            |\n| `packages/http/src/mocker/index.ts`    | Mock response generation entrypoint            |\n| `packages/http/src/validator/index.ts` | Validation entrypoint                          |\n| `packages/http/src/router/index.ts`    | Matches requests to OpenAPI operations         |\n| `packages/http/src/forwarder/index.ts` | Upstream proxy forwarding                      |\n| `packages/cli/src/commands/`           | `mock` and `proxy` CLI command implementations |\n| `packages/http-server/src/index.ts`    | HTTP server setup                              |\n\n## Testing\n\n- Tests live in `__tests__/` directories alongside source files, named `*.spec.ts` or `*.test.ts`\n- Jest projects are scoped per package: `HTTP-SERVER`, `HTTP`, `CORE`, `CLI`\n- `nock` is used for HTTP mocking in tests\n- Harness tests (`packages/cli/src/__tests__/harness/`) test the compiled binary end-to-end\n\n## Code Style\n\n- Prettier: 120-char line width, single quotes, trailing commas (es5)\n- ESLint with `@typescript-eslint` — `lint-staged` auto-fixes on commit via Husky\n- Arrow functions: omit parens for single parameter\n- TypeScript strict mode; `ttypescript` (ttsc) is used for compilation with custom transformers\n\n## Branch & Release\n\n- Feature branches: `feature/*`, `chore/*`, `fix/*`\n- Releases managed via Lerna (`npm run release`)\n- Node.js minimum: 18.20.1\n\n<!-- File: packages/cli/README.md (Tokens: ~454 | Category: plugin-manifest) -->\n# prism-cli\n\nYou can install the command line CLI using `npm i -g @stoplight/prism-cli`\n\nTo get an overview of all the commands, just do `prism help`\n\n## Documentation\n\nRead me about the [Prism CLI](../../docs/getting-started/03-cli.md).\n\n## Development\n\n### Debugging\n\n1. `npm run cli:debug -- mock file.oas.yml`\n2. Run your preferred debugger on the newly created process. If you're into VS Code, you can create `.vscode/launch.json` and put this content inside:\n\n```json\n{\n  \"type\": \"node\",\n  \"request\": \"attach\",\n  \"name\": \"Attach\",\n  \"port\": 9229\n},\n```\n\n4. Enjoy the breakpoints :)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5a343b5d-430b-4fea-8299-845b23c0b407&page=README.md\" />\n\n<!-- File: packages/core/README.md (Tokens: ~331 | Category: plugin-manifest) -->\n# Prism Core\n\nThis package contains base abstract interfaces. Generally, you do not want to look at this repository, as there's nothing more than philosophycal reasonments that aren't exactly that pragmatic.\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=d703ffa4-a736-40cc-a994-9116c1e7e4d8&page=README.md\" />\n\n<!-- File: packages/http-server/README.md (Tokens: ~504 | Category: plugin-manifest) -->\n# Prism Server\n\n**NOTE:** The current API is still experimental and could change with no notice. Use at your own risk.\n\nUsage:\n\n```javascript\nconst { createServer } = require('@stoplight/prism-http-server');\nconst { getHttpOperationsFromSpec } = require('@stoplight/prism-cli/dist/operations');\nconst { createLogger } = require('@stoplight/prism-core');\n\nasync function createPrismServer() {\n  const operations = await getHttpOperationsFromSpec('YOUR-URL');\n\n  const server = createServer(operations, {\n    components: {\n      logger: createLogger('TestLogger'),\n    },\n    cors: true,\n    config: {\n      checkSecurity: true,\n      validateRequest: true,\n      validateResponse: true,\n      mock: { dynamic: false },\n      isProxy: false,\n      errors: false,\n    },\n  });\n  await server.listen(4010);\n\n  return {\n    close: server.close.bind(server),\n  };\n}\n\nconst server = await createPrismServer();\n\nserver.close();\n```\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=6cab5318-35c8-4dff-b6de-7007ba44442c&page=README.md\" />\n\n<!-- File: packages/http/README.md (Tokens: ~2531 | Category: plugin-manifest) -->\n# HTTP Client\n\nThis package provides a HTTP client featuring the ability to:\n\n- mock responses based of OpenAPI spec\n- make requests to a HTTP server\n- validate the request and/or the response according to the provided OpenAPI Specification file\n\nIn essence it's an HTTP client with the ability to mock responses and validate requests.\n\nThe goal of this document is to provide you with some basic code examples to get you started and to cover some of the advanced scenarios.\n\n## Important\n\nIf you're a regular user and not a PRO, you might to want to use the [User facing client](../../docs/guides/07-http-client.md) which provides a better an higher lever API\n\n# Table of Contents\n\n- [Installation](#installation)\n- [Basic Usages](#basic-usages)\n  - [Mock All Responses](#mock-all-responses)\n  - [Mock Single Response](#mock-single-response)\n  - [Make Request To An Upstream Server](#make-request-to-an-upstream-server)\n- [Advanced Topics](#advanced-topics)\n  - [Creating Prism Instance](#creating-prism-instance)\n    - [Config Object](#config-object)\n      - [Config Examples](#config-examples)\n  - [Loading specs](#loading-specs)\n  - [Making requests](#making-requests)\n    - [Server Validation](#server-validation)\n  - [Understanding response](#understanding-response)\n  - [Prism Decision Flow Diagram](#prism-decision-flow-diagram)\n- [Anonymized analytics](#anonymized-analytics)\n\n# Installation\n\n```bash\nnpm install @stoplight/prism-http\n```\n\n# Basic Usages\n\n> Note: the examples in this document use the following spec\n\n```yaml\nopenapi: 3.0.2\npaths:\n  /todos:\n    get:\n      parameters:\n        - name: title\n          in: query\n          style: form\n          schema:\n            enum:\n              - eat\n              - drink\n      responses:\n        200:\n          description: Get Todo Items\n          content:\n            'text/plain':\n              example: Write great OpenAPI specs!\n```\n\n## Mock All Responses\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it as a mocker generating static examples\nconst prism = Prism.createInstance({\n  mock: { dynamic: false },\n  validate: { request: { query: true } },\n});\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/todos',\n    },\n    headers: {\n      Accept: 'text/plain',\n    },\n  },\n  operations\n);\n```\n\nOutput\n\n```bash\n{\n  statusCode: 200,\n  headers: { 'Content-type': 'text/plain' },\n  body: 'Write great OpenAPI specs!'\n}\n```\n\nNote: the `request` method returns a [`TaskEither` monad](https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html). So in case you want to extract the result, you're going to need to use the [pipe](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) function.\n\n```ts\nreturn pipe(\n  prism.request(\n    {\n      method: 'get',\n      url: {\n        path: '/todos',\n      },\n      headers: {\n        Accept: 'text/plain',\n      },\n    },\n    operations\n  ),\n  TE.fold(console.error, console.log)\n)(); // returns a Promise\n```\n\n## Mock Single Response\n\nIn the following example we will first instantiate Prism to make requests to an actual server.\n\nLater we alter than behaviour by passing a config object to the `request` function.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Note that by default we don't want to mock responses\nconst prism = Prism.createInstance({ mock: { dynamic: false } });\n\n// Make a \"GET /todos\" request\nreturn prism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  {\n    // We can override the default behaviour per request.\n    mock: {\n      dynamic: true,\n    },\n  },\n  operations\n);\n```\n\n## Make Request To An Upstream Server\n\nWe don't want to mock a reqeust, we simply want to make the request, hit the actual server and get the response back.\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make HTTP requests (mock: {dynamic: false})\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\n\nreturn prism.request({\n  method: 'get',\n  url: {\n    path: '/facts',\n    baseUrl: 'https://cat-fact.herokuapp.com',\n  },\n});\n```\n\nIn response you'll get some... facts about cats. For example:\n\n> Cats aren’t the only animals that purr — squirrels, lemurs, elephants, and even gorillas purr too.\n\n:)\n\n# Advanced Topics\n\n## Creating Prism Instance\n\nIn order to create and instance of HTTP Client (later referred to as `prism` for simplicity) use the `createInstance` function, like so:\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config /*, components */);\n```\n\nThere are two (both optional) arguments you can supply `createInstance` with:\n\n- config (of `IHttpConfig` type)\n- components (of `PrismHttpComponents` type)\n\nWe will cover the `config` argument in next section and we'll leave `components` for some other time (overriding default `components` is the _ultimate advanced stuff_).\n\n### Config Object\n\nPrism's config object (`IHttpConfig`) allows you to manipulate Prism's behaviour in many ways. For instance:\n\n- turn validation on and off\n- influence Prism's mocked response generation strategy\n\nThe actual interface looks like this (but rather than explain each property we're going to look at some examples)\n\n```ts\nexport interface IHttpConfig extends IPrismConfig {\n  mock: { dynamic: false } | IHttpOperationConfig;\n  validateRequest: boolean;\n  validateResponse: boolean;\n  checkSecurity: boolean;\n  errors: boolean;\n}\n```\n\n#### Config Examples\n\n**When mocking a response generate static response**\n\n```javascript\nconst config = {\n  mock: {\n    dynamic: false,\n  },\n};\n```\n\nGenerating static responses means that if an OpenAPI operation's response has any examples defined the payload we construct will use those examples.\n\nThis contrasts \"dynamic responses\" which means generating responses from a json schema.\n\n**Return named example of a specified key**\n\n```javascript\nconst config = {\n  mock: {\n    exampleKey: 'key',\n  },\n};\n```\n\nIn OpenAPI Specification 3 one can construct such response that will have multiple examples mapped by keys.\nThis configuration allows you to be very specific which example you want to choose.\n\n**Return 403 response of specified mime type**\n\n```javascript\nconst config = {\n  mock: {\n    code: 403,\n    mediaTypes: ['application/xml'],\n  },\n};\n```\n\nThis will enforce a 403 response (given that such response is defined in your OpenAPI file).\n\n## Loading specs\n\nThe Http package does not have any pre-canned loader for the specification files. You need to feed it with an array of operations that can be used for the request/response cycle.\n\nYou can find an example by looking at the [operations.ts](../cli/src/operations.ts) file in the CLI package.\n\n## Making requests\n\nTo make a basic request you need to do the following\n\n```javascript\nconst request = {\n  method: 'get',\n  url: {\n    path: '/path', // must be prefixed with slash\n  },\n};\nconst promise = prism.request(request, operations);\n```\n\nThe request object has the following interface\n\n```ts\nexport interface IHttpRequest {\n  method: HttpMethod;\n  url: IHttpUrl;\n  headers?: IHttpNameValue;\n  body?: unknown;\n}\n```\n\nAll of this is pretty standard except the `url.baseUrl` which we will describe in more details.\n\n### Server Validation\n\nConsider a request\n\n```javascript\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts', // must be prefixed with slash\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nNotice that `baseUrl` is defined.\n\nThis will instruct Prism to do one of the two:\n\n- if mocking is **disabled** (`{ mock: {dynamic: false} }`)\n  - it will use that `baseUrl` to make a request to the server (`GET https://cat-fact.herokuapp.com/facts`)\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **add an input warning to the .request return value if it is not valid**\n- if mocking is **enabled**\n  - it will **verify** whether the provided `baseUrl` matches any of the servers defined in your OpenAPI and **return an error if it is not valid**\n\n## Understanding response\n\nThe `prism.request` resolved (it's a Promise!) value consists of:\n\n- input - copy of the request object you provided\n- output - the HTTP response\n- validations\n  - input - list of warnings/errors related to you http request object\n  - output - list of warnings/errors related to you http response object\n\nValidations are still subject of tests and experimentation therefore we will not cover them fully for the time being.\n\nOne example however is that for a given example\n\n```javascript\nconst Prism = require('@stoplight/prism-http');\n\n// Create Prism instance and configure it to make http requests\nconst config = { mock: { dynamic: false } };\nconst prism = Prism.createInstance(config);\nprism.request(\n  {\n    method: 'get',\n    url: {\n      path: '/facts',\n      baseUrl: 'https://cat-fact.herokuapp.com',\n    },\n  },\n  operations\n);\n```\n\nYou would get this in response\n\n```bash\n[\n  {\n    message: 'Route not resolved, no resource provided.',\n    source: 'https://stoplight.io/prism/errors#NO_RESOURCE_PROVIDED_ERROR',\n    code: 404,\n    severity: 1\n  }\n]\n```\n\n## Prism Decision Flow Diagram\n\nThe below diagram represents all logical decision we make to figure out the best HTTP response to the specific request.\n\n![Decision Flow Diagram](./docs/images/mock-server-dfd.jpeg)\n\n## Anonymized analytics\n\nPrism uses [Scarf](https://scarf.sh/) to collect [anonymized installation analytics](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-what-information-does-scarf-js-send-about-me). These analytics help support the maintainers of this library and ONLY run during installation. To [opt out](https://github.com/scarf-sh/scarf-js?tab=readme-ov-file#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics), you can set the `scarfSettings.enabled` field to `false` in your project's `package.json`:\n\n```\n// package.json\n{\n  // ...\n  \"scarfSettings\": {\n    \"enabled\": false\n  }\n  // ...\n}\n```\n\nAlternatively, you can set the environment variable `SCARF_ANALYTICS` to `false` as part of the environment that installs your npm packages, e.g., `SCARF_ANALYTICS=false npm install`.\n\n<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=872f5d30-d243-4e27-9afc-e21416a841be&page=README.md\" />\n</yakaai_skills>"}