{"id":16184601,"url":"https://github.com/rmariuzzo/fixture-middleware","last_synced_at":"2025-04-02T00:31:53.317Z","repository":{"id":57237732,"uuid":"111837048","full_name":"rmariuzzo/fixture-middleware","owner":"rmariuzzo","description":"Use fixture data in your express app!","archived":false,"fork":false,"pushed_at":"2017-12-12T14:36:05.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T03:23:01.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/rmariuzzo.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}},"created_at":"2017-11-23T17:48:04.000Z","updated_at":"2018-12-05T14:56:08.000Z","dependencies_parsed_at":"2022-08-26T14:04:22.444Z","dependency_job_id":null,"html_url":"https://github.com/rmariuzzo/fixture-middleware","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffixture-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffixture-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffixture-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmariuzzo%2Ffixture-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmariuzzo","download_url":"https://codeload.github.com/rmariuzzo/fixture-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246720428,"owners_count":20822899,"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":[],"created_at":"2024-10-10T07:10:40.565Z","updated_at":"2025-04-02T00:31:52.747Z","avatar_url":"https://github.com/rmariuzzo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![fixture-middleware — Use fixture data in your express app!](banner.svg)\n\n## Motivation\n\nSometimes I want to mock certain paths of my API made with [Express](http://expressjs.com/). Therefore, I created **fixture-middleware** which will use fixture data (mock) for any URL that matches a file inside the configured fixture directory.\n\n## Installation\n\n```shell\nnpm install fixture-middleware --save-dev\n```\n\n```shell\nyarn add fixture-middleware --dev\n```\n\n## Usage\n\n```js\nconst path = require('path')\nconst express = require('express')\nconst fixtureMiddleware = require('fixture-middleware')\n\nconst app = express()\nconst fixtureDirectory = path.resolve(__dirname, './fixtures')\n\napp.use(fixtureMiddleware(fixtureDirectory))\n```\n\n### Matching URLs with fixture files\n\nAll URLs are normalized (all `/` will be replaced by `--`) and if a `Accept` headers is present it will be used to determine the file extension, otherwise the first matching file will be returned.\n\n#### Example\n\nSuppose we have the following files in the configured fixture directory:\n\n```\n`-- fixtures\n    |-- users.json\n    |-- users.html\n    `-- users--active.json\n```\n\nThe following request will match those files as follows\n\n | Request | Response\n | ---     | ---\n | **URL:** `/users` \u003cbr\u003e **Headers:** (no accept header)               | **File:** `users.html`\n | **URL:** `/users` \u003cbr\u003e **Headers:** `accept=application.json`        | **File:** `users.json`\n | **URL:** `/users` \u003cbr\u003e **Headers:** `accept=application.html`        | **File:** `users.html`\n | **URL:** `/users/active` \u003cbr\u003e **Headers:** (no accept header)        | **File:** `users--active.json`\n | **URL:** `/users/active` \u003cbr\u003e **Headers:** `accept=application.json` | **File:** `users--active.json`\n\n**Important:** Any unmatched request will be delegated to the next middleware.\n\n## Development\n\n  1. Clone and fork this repo.\n  2. Install dependencies: yarn or npm install.\n  3. [Run tests](#test).\n  4. Prepare a pull request.\n\n### Test\n\n  - `yarn test` – to run all tests.\n  - `yarn test -- --watch` – to run all tests in watch mode.\n\n### Publish\n\n  1. Bump package version: `yarn version --new-version x.x.x -m 'Version %s.'`.\n  2. Publish to NPM registry: `npm publish`.\n  3. Push new tag: `git push origin --tags`.\n\n---\n\n\u003cdiv align=center\u003e\n\nMade with :heart: by [Rubens Mariuzzo](https://github.com/rmariuzzo).\n\n[MIT license](LICENSE)\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Ffixture-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmariuzzo%2Ffixture-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmariuzzo%2Ffixture-middleware/lists"}