{"id":13989937,"url":"https://github.com/uber/eight-track","last_synced_at":"2025-07-22T11:32:21.723Z","repository":{"id":12946107,"uuid":"15624141","full_name":"uber/eight-track","owner":"uber","description":"Record and playback HTTP requests","archived":true,"fork":false,"pushed_at":"2018-07-21T00:04:09.000Z","size":1138,"stargazers_count":70,"open_issues_count":4,"forks_count":18,"subscribers_count":2752,"default_branch":"master","last_synced_at":"2024-08-09T13:16:45.674Z","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/uber.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-04T01:46:30.000Z","updated_at":"2023-06-19T00:33:09.000Z","dependencies_parsed_at":"2022-09-01T12:21:05.465Z","dependency_job_id":null,"html_url":"https://github.com/uber/eight-track","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Feight-track","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Feight-track/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Feight-track/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uber%2Feight-track/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uber","download_url":"https://codeload.github.com/uber/eight-track/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227089478,"owners_count":17729471,"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-08-09T13:02:11.273Z","updated_at":"2024-11-29T09:30:37.673Z","avatar_url":"https://github.com/uber.png","language":"JavaScript","readme":"# eight-track [![Build status](https://travis-ci.org/uber/eight-track.png?branch=master)](https://travis-ci.org/uber/eight-track)\n\nRecord and playback HTTP requests\n\nThis is built to make testing against third party services a breeze. No longer will your test suite fail because an external service is down.\n\n\u003e `eight-track` is inspired by [`cassette`][] and [`vcr`][]\n\n[`cassette`]: https://github.com/uber/cassette\n[`vcr`]: https://rubygems.org/gems/vcr\n\n## Active forks\n`eight-track` has been forked by [@twolfson][] as [`nine-track`][]. This includes new features such as `scrubFn` for sanitizing data before saving to disk.\n\n[@twolfson]: https://github.com/twolfson\n[`nine-track`]: https://github.com/twolfson/nine-track\n\n## Getting Started\nInstall the module with: `npm install eight-track`\n\n```javascript\n// Start up a basic applciation\nvar express = require('express');\nvar eightTrack = require('eight-track');\nvar request = require('request');\nexpress().use(function (req, res) {\n  console.log('Pinged!');\n  res.send('Hello World!');\n}).listen(1337);\n\n// Create a server using a `eight-track` middleware to the original\nexpress().use(eightTrack({\n  url: 'http://localhost:1337',\n  fixtureDir: 'directory/to/save/responses'\n})).listen(1338);\n\n// Hits original server, triggering a `console.log('Pinged!')` and 'Hello World!' response\nrequest('http://localhost:1338/', console.log);\n\n// Hits saved response but still receieves 'Hello World!' response\nrequest('http://localhost:1338/', console.log);\n```\n\n## Documentation\n`eight-track` exposes `eightTrack` as its `module.exports`.\n\n### `eightTrack(options)`\nMiddleware creator for new `eightTrack's`. This *is not* a constructor.\n\n- options `Object` - Container for parameters\n    - url `String|Object` - URL of a server to proxy to\n        - If it is a string, it should be the base URL of a server\n        - If it is an object, it should be parameters for [`url.format`][]\n    - fixtureDir `String` - Path to load/save HTTP responses\n        - Files will be saved with the format `{{method}}_{{encodedUrl}}_{{hashOfRequestContent}}.json`\n        - An example filename is `GET_%2F_658e61f2a6b2f1ae4c127e53f28dfecd.json`\n    - normalizeFn `Function` - Function to adjust `request's` save location signature\n        - If you would like to make two requests resolve from the same response file, this is how.\n        - The function signature should be `function (info)` and can either mutate the `info` or return a fresh object\n        - `info` will have the following properties\n             - httpVersion `String` - HTTP version received from `request` (e.g. `1.0`, `1.1`)\n             - headers `Object` - Headers received by `request`\n             - trailers `Object` - Trailers received by `request`\n             - method `String` - HTTP method that was used (e.g. `GET`, `POST`)\n             - url `String` - Pathname that `request` arrived from\n             - body `Buffer` - Buffered body that was written to `request`\n        - Existing `normalizeFn` libraries (e.g. `multipart/form-data` can be found below)\n\n[`url.format`]: http://nodejs.org/api/url.html#url_url_format_urlobj\n\n`eightTrack` returns a middleware with the signature `function (req, res)`\n\n```js\n// Example of string url\neightTrack({\n  url: 'http://localhost:1337',\n  fixtureDir: 'directory/to/save/responses'\n});\n\n// Example of object url\neightTrack({\n  url: {\n    protocol: 'http:',\n    hostname: 'localhost',\n    port: 1337\n  },\n  fixtureDir: 'directory/to/save/responses'\n});\n```\n\nIf you need to buffer the data before passing it off to `eight-track` that is supported as well.\nThe requirement is that you record the data as a `Buffer` or `String` to `req.body`.\n\n#### `normalizeFn` libraries\n- `multipart/form-data` - Ignore randomly generated boundaries and consolidate similar `multipart/form-data` requests\n    - Website: https://github.com/twolfson/eight-track-normalize-multipart\n\n### `eightTrack.forwardRequest(req, cb)`\nForward an incoming HTTP request in a [`mikeal/request`][]-like format.\n\n- req `http.IncomingMessage` - Inbound request to an HTTP server (e.g. from `http.createServer`)\n    - Documentation: http://nodejs.org/api/http.html#http_http_incomingmessage\n- cb `Function` - Callback function with `(err, res, body)` signature\n    - err `Error` - HTTP error if any occurred (e.g. `ECONNREFUSED`)\n    - res `Object` - Container that looks like an HTTP object but simiplified due to saving to disk\n        - httpVersion `String` - HTTP version received from external server response (e.g. `1.0`, `1.1`)\n        - headers `Object` - Headers received by response\n        - trailers `Object` - Trailers received by response\n        - statusCode `Number` - Status code received from external server response\n        - body `Buffer` - Buffered body that was written to response\n    - body `Buffer` - Sugar variable for `res.body`\n\n[`mikeal/request`]: https://github.com/mikeal/request\n\n## Examples\n### Proxy server with subpath\n`eight-track` can talk to servers that are behind a specific path\n\n```js\n// Start up a server that echoes our path\nexpress().use(function (req, res) {\n  res.send(req.path);\n}).listen(1337);\n\n// Create a server using a `eight-track` middleware to the original\nexpress().use(eightTrack({\n  url: 'http://localhost:1337/hello',\n  fixtureDir: 'directory/to/save/responses'\n})).listen(1338);\n\n// Logs `/hello/world`, concatenated result of `/hello` and `/world` pathss\nrequest('http://localhost:1338/world', console.log);\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via [grunt](https://github.com/gruntjs/grunt) and test via `npm test`.\n\n## License\nCopyright (c) 2014 Uber\n\nLicensed under the MIT license.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuber%2Feight-track","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuber%2Feight-track","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuber%2Feight-track/lists"}