{"id":13465030,"url":"https://github.com/flickr/yakbak","last_synced_at":"2025-05-15T11:07:25.684Z","repository":{"id":7990077,"uuid":"54654357","full_name":"flickr/yakbak","owner":"flickr","description":"Record and playback HTTP responses","archived":false,"fork":false,"pushed_at":"2022-02-11T23:24:53.000Z","size":104,"stargazers_count":1053,"open_issues_count":26,"forks_count":83,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-04-07T13:01:46.654Z","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/flickr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T15:49:24.000Z","updated_at":"2025-02-11T21:32:31.000Z","dependencies_parsed_at":"2022-08-06T20:15:25.776Z","dependency_job_id":null,"html_url":"https://github.com/flickr/yakbak","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flickr%2Fyakbak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flickr%2Fyakbak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flickr%2Fyakbak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flickr%2Fyakbak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flickr","download_url":"https://codeload.github.com/flickr/yakbak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248911930,"owners_count":21182179,"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-07-31T14:00:55.478Z","updated_at":"2025-04-14T15:54:25.699Z","avatar_url":"https://github.com/flickr.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# yakbak\n\nRecord HTTP interactions The Node Way™. Inspired by ruby's [vcr][1].\n\n\u003e [![Build Status](https://travis-ci.org/flickr/yakbak.svg?branch=master)](https://travis-ci.org/flickr/yakbak)\n\n## install\n\n``` bash\n$ npm install yakbak --save-dev\n```\n## usage\n\nThe main idea behind testing HTTP clients with yakbak is:\n\n1. Make your client's target host configurable.\n2. Set up a yakbak server locally to proxy the target host.\n3. Point your client at the yakbak server.\n\nThen develop or run your tests. If a recorded HTTP request is found on disk, it will be played back instead of hitting the target host. If no recorded request is found, the request will be forwarded to the target host and recorded to disk.\n\n### yakbak(host, options)\n\nReturns a function of the signature `function (req, res)` that you can give to an `http.Server` as its handler.\n\n``` js\nvar handler = yakbak('http://api.flickr.com', {\n\tdirname: __dirname + '/tapes'\n});\n```\n\n#### options\n\n- `dirname` the path where recorded responses will be written (required).\n- `noRecord` if true, requests will return a 404 error if the tape doesn't exist\n- `hash(req, body)` provide your own IncomingMessage hash function\n\n### with node's http module\n\nyakbak provides a handler with the same signature that `http.Server` expects so you can create your own proxy:\n\n``` js\nvar http = require('http');\nvar yakbak = require('yakbak');\n\nhttp.createServer(yakbak('http://api.flickr.com', {\n\tdirname: __dirname + '/tapes'\n})).listen(3000);\n```\n\nNow any requests to `http://localhost:3000` will be proxied to `http://api.flickr.com` and recorded to `/tapes` for future playback.\n\n### with express\n\nNeed more flexibility? [express](https://github.com/expressjs/express) expects the same function signature, so you can use yakbak just like you would any other middleware:\n\n``` js\nvar express = require('express');\nvar yakbak = require('yakbak');\n\nvar flickr = yakbak('http://api.flickr.com', {\n\tdirname: __dirname + '/tapes'\n});\n\nvar upload = yakbak('http://up.flickr.com', {\n\tdirname: __dirname + '/tapes'\n});\n\nexpress().use(function (req, res, next) {\n\tif (req.path.indexOf('/services/upload') === 0) {\n\t  upload(req, res);\n\t} else {\n\t  flickr(req, res);\n\t}\n}).listen(3000);\n```\n\n### as a standalone response server\n\nEach recorded response is itself a node module with the same handler signature, so if you want to create a server that replays a single response, you can do so easily:\n\n``` js\nvar http = require('http');\nvar tape = require('./tapes/1117f3d81490d441d826dd2fb26470f9.js');\n\nhttp.createServer(tape).listen(3000);\n```\n\n### on the command line\n\nyakbak also ships with a `yakbak` utility that will start an HTTP server to play back a given tape.\n\n``` bash\n$ yakbak\nError: file is required\nUsage: yakbak \u003cfile\u003e\n$ yakbak ./tapes/1117f3d81490d441d826dd2fb26470f9.js\nServer listening on port 3000\n* Connection from 127.0.0.1 port 63669\n\u003c GET / HTTP/1.1\n\u003c host: localhost:3000\n\u003c user-agent: curl/7.43.0\n\u003c accept: */*\n\u003c\n\u003e HTTP/1.1 201 Created\n\u003e content-type: text/html\n\u003e date: Sat, 26 Oct 1985 08:20:00 GMT\n\u003e connection: close\n\u003e transfer-encoding: chunked\n\u003e\n* Connection closed\n```\n\n## why not [insert other project here]?\n\nCheck out [this blog post][2] about why we chose a reverse proxy over other existing approaches to recording HTTP interactions.\n\n## license\n\nThis software is free to use under the MIT license. See the [LICENSE][] file for license text and copyright information.\n\n[1]: https://github.com/vcr/vcr\n[2]: http://code.flickr.net/2016/04/25/introducing-yakbak-record-and-playback-http-interactions-in-nodejs/\n[LICENSE]: https://github.com/flickr/yakbak/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflickr%2Fyakbak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflickr%2Fyakbak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflickr%2Fyakbak/lists"}