{"_id":"handler-agent","_rev":"3-cec0a92c6ca8e06494c528fe386ad824","name":"handler-agent","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"handler-agent","version":"0.1.0","description":"Zero-dependency (req,res) handler callback agent for use in client requests","main":"index.js","repository":{"type":"git","url":"git+https://github.com/qix-/handler-agent.git"},"scripts":{"test":"xo && best -v -I test/*.js"},"keywords":["http","agent","server","api","tests","testing","tester","handler","rest","endpoint"],"xo":{"rules":{"unicorn/prevent-abbreviations":0}},"author":{"name":"Josh Junon","email":"josh@junon.me"},"license":"MIT","devDependencies":{"@zeit/best":"0.6.1","got":"11.0.3","xo":"0.30.0"},"gitHead":"b1f587cec70f570dd7a2a8490a6608be334b394e","bugs":{"url":"https://github.com/qix-/handler-agent/issues"},"homepage":"https://github.com/qix-/handler-agent#readme","_id":"handler-agent@0.1.0","_nodeVersion":"13.9.0","_npmVersion":"6.13.7","dist":{"integrity":"sha512-y9jdJrT146x5eJ74g8LFvM5vsr2sWWHEpy+Ha0kvu7EjyuTwCsi2OxHnMzozbO/3hdeeobi9CRDYFSi2V4u/eg==","shasum":"537073c2c54c57c5b34e6bcb4d70532e90e9bd5b","tarball":"https://registry.npmjs.org/handler-agent/-/handler-agent-0.1.0.tgz","fileCount":4,"unpackedSize":4684,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJerFdACRA9TVsSAnZWagAA6fYP/i+B3Lj7A1bAKFyMN2l5\ncSplfOdwlNa6ZkCA3Q6Kg4fJKVG8Yf+KShcDxEQMVwhIHOa6V6yfG+j+sHe1\nGQaG/LOonrEuttT81Nh/yjNg3Q+co+uKgXMlmJqBEUC9SR4MpHISBJ06R5v5\nl/IyCx1KcVvXQsAA3YJNqvRj06uxSdq799mEWUyl0zLVZ8EucIBJyd1pNQ30\nKxGOLBXQ2Jy9ky3b6sHW1SgpHet0zLXrI7HEnr1wmt9kr+UWFbfGPIg2HfeP\njNUR9qVMNujXJKvuHlEg6Oz+v2ptaJvfXCAm52faZRlmOekyHIiXDNHZrt7S\n2qk0viEsDjPhoKiwEUU63xPKAWRUwwUxMY2P7cbM/BMikrsQkOHHbX2fKah5\nQiIfQMMI51fsz53glCXH1WUPdGAw/1oqMWmwExExRyToMLixjwnx9ki/wZTg\nA+WCw5NLY08ASWn1skc60eCpe3eKPFXQUyS32XLYOEHEtQDo/eKD/eR6vcjk\nySKP+ks/NLMqIOUifpwZhtel4ODs0ZR62fQhT+TNWuHimrBpdg08TLftkzDT\nghQVDNonfBI4SY+A92xgeQctvz6hHe7C+tx898ylhnLFYB0kelHhX0uWG37A\n/mPihRceSeDD1FnTs4BA05078tICSxcHXPw2ZVg1ILZbNJOjTi12zK55LVii\ngALV\r\n=ZLsi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCtsVzFqsOIM6iijAI4Oylsu5GS3Cr8Q9LtAJaGxQ89CwIhAITTqhQk+Xs5XYU9giWG6HsmyZRnhBd/vfo7saID4D1V"}]},"maintainers":[{"name":"qix","email":"i.am.qix@gmail.com"}],"_npmUser":{"name":"qix","email":"i.am.qix@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/handler-agent_0.1.0_1588352832266_0.5355879313600274"},"_hasShrinkwrap":false},"0.1.1":{"name":"handler-agent","version":"0.1.1","description":"Zero-dependency (req,res) handler callback agent for use in client requests","main":"index.js","repository":{"type":"git","url":"git+https://github.com/qix-/handler-agent.git"},"scripts":{"test":"xo && best -v -I test/*.js"},"keywords":["http","agent","server","api","tests","testing","tester","handler","rest","endpoint"],"xo":{"rules":{"unicorn/prevent-abbreviations":0}},"author":{"name":"Josh Junon","email":"josh@junon.me"},"license":"MIT","devDependencies":{"@zeit/best":"0.6.1","got":"11.0.3","xo":"0.30.0"},"gitHead":"3f9f354f9c4d7b8af07b1c19eaa12cc34edc7955","bugs":{"url":"https://github.com/qix-/handler-agent/issues"},"homepage":"https://github.com/qix-/handler-agent#readme","_id":"handler-agent@0.1.1","_nodeVersion":"13.9.0","_npmVersion":"6.13.7","dist":{"integrity":"sha512-RdMTjkqRquAaH8bYpQ5ImBrzgoJPf8OAvtPeo+Z5hngSJNaXwCmB6EhIWC+rFsHdCXytKjKny8p3bnCWmux65Q==","shasum":"f720eb3150cb62880ebf336274e5202a77a78768","tarball":"https://registry.npmjs.org/handler-agent/-/handler-agent-0.1.1.tgz","fileCount":4,"unpackedSize":4811,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJerF+KCRA9TVsSAnZWagAAdvcP/jxhiM8HVF/cGO5ZwP1U\nXhLfeayqMOEGz6bb75Eth3c4DNqt7C/zxRu/G+uHnORMxqil1S0LVhUj69gF\nc3mq4rZtpCUwEF2UxxyFOozaCev9l1DoPM+xKGlNhn6/BvNIs75OE7mYWrsJ\nJvjn2hYU6nKLl2KmfBk+QGBaOUH6fiYITLul/QUiuUJEeHsYZzYtXL0/68WR\nRhJlqsU/ElYUBV/QiGgMJkZccH+ufAksiQblQBL5RYK0oAprbn8dbzgvEoBo\nm7ZmF7YHSA9rnoeWxT+JK07nr2upTNW876C7K4zQ6nN6jwXZ2bj9iJeg5sxk\ni+jsK47A/rDCWb9kwAjnDELw0fabcG0Gtn6iKUohMW8hpPO8YdMTgRkZjExd\nxn+oCbdEtSStQ0PytQa94GSPdAxr2GGGlsM0nmn+nu4oFSMd6l40er8xmaNE\n8DwsxqRqrT47Lnz4l5xW92hj4hQChCDomJNZAtYqnDIVg1EjR6sszL9AfEE7\nXkMziLD4uHsmCtN/dbBgToOD20NFVboEM/hsNNWe8o7gtU+xNOi8t7jBA4BK\n4cPB0EOP3N/1E7z6e0A+CLgTTdRDYOXYtbycjTdk6Dy2qFj4YFM8GUKpC1Bv\nZFeb4D+/zoIgLKhcG7wV1Z9ovkaueTlcH3SULqObJ+4AxIPT4FFf9Qq2vaJ0\ngw49\r\n=v8eK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIErJAMZQzcla9nBDh5DjkpkX7+OqTPDNQgo9rkfpreB9AiA1HVFSV5U7Ix0iPtosx3M2TdlPhlxLvGTNOhGMZbUMkQ=="}]},"maintainers":[{"name":"qix","email":"i.am.qix@gmail.com"}],"_npmUser":{"name":"qix","email":"i.am.qix@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/handler-agent_0.1.1_1588354953920_0.39279192720704836"},"_hasShrinkwrap":false},"0.2.0":{"name":"handler-agent","version":"0.2.0","description":"Zero-dependency (req,res) handler callback agent for use in client requests","main":"index.js","repository":{"type":"git","url":"git+https://github.com/qix-/handler-agent.git"},"scripts":{"test":"xo && best -v -I test/*.js"},"keywords":["http","agent","server","api","tests","testing","tester","handler","rest","endpoint"],"xo":{"rules":{"unicorn/prevent-abbreviations":0}},"author":{"name":"Josh Junon","email":"josh@junon.me"},"license":"MIT","devDependencies":{"@zeit/best":"0.6.1","got":"11.0.3","xo":"0.30.0"},"gitHead":"b82c7cf5752f91ba0f47f7c9c029181a47174260","bugs":{"url":"https://github.com/qix-/handler-agent/issues"},"homepage":"https://github.com/qix-/handler-agent#readme","_id":"handler-agent@0.2.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","dist":{"integrity":"sha512-cUduQxa5p3TFtGmb55mrRbkk/3EJCsLSeFrCIuTakQHQlYVWXeW2L9IUQUHyoHLI4UgpBNaN2JrZ0He1jPu+vg==","shasum":"bb77cd70b60bd7073b5327a7c3dbaec9420165d4","tarball":"https://registry.npmjs.org/handler-agent/-/handler-agent-0.2.0.tgz","fileCount":5,"unpackedSize":5025,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfTi8QCRA9TVsSAnZWagAAJz0QAIVXnvQ0oEOAOcBoYoEo\nZJ4Uxmisl51RGCUkcMWIhZ14UGhksGOiHq3vuCfelJ23DyGcuMH8NJvqo8EC\nKdydfvRpZ0qloU3iyNo6p9vVwurAZXz6QBiF3/k+S15BG1jCKzxwkij6XAUr\nzDuN5ErVtEXbN4EyiKx78juHIsW1X7ap1UA6td7QS3r3wUJkFykxBt9BH4dh\noIEBqPrIeWy1n00VzJ3QqVjKbhfq4bxCqEDe6VfyOueMR0fUnJdAKvy/yrHT\nTX48y13VjyBdBgRtDI8pc5iJdThHvZ01Wc+F3Hr0SrzRjARz0CaEjacd58AG\n3AyH8PPO48tgB0VQPLuAcQhfOuFyMeYMncwKB0J2LW51YaNa3RtX7lU7ZfL/\nF0FC0lfsfVmsmfZU/gBeA8pqpdAElswregaU96d6JN0tcjnUY3Za9sTVB6pM\n3fimH9gMoZfE0KV0Wut7sY0KtrarttAeZbjwTd5QTbQdu3+Xi1slS8kBrzXe\nqp49YnciGdsquvrAIihcAO8ajndqr3M6hf9ikn/3S3uO0N816OE6YcjS31sa\nvDvpauXKDRczjPcKt9OVWTXKZZIJzk3VMA/P89CUz7ur+9td/BnN3VFv5r+G\nhniTWffaEVDfl1j+rKwgKTFN/6PxbtzyfbGouTS1uCgYC3gdNZn52XQ1q5r+\nwKmt\r\n=Vdii\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDI3+dix3gAtEmf88tc2INuhezWceDxo1ze5XED7Z9DgAiEAw1ybui1fqfxm0Ymxo79rjzYQXfhVjVBweW4BWJsL7wQ="}]},"maintainers":[{"name":"qix","email":"i.am.qix@gmail.com"}],"_npmUser":{"name":"qix","email":"i.am.qix@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/handler-agent_0.2.0_1598959376406_0.601199688483717"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-01T17:07:12.266Z","0.1.0":"2020-05-01T17:07:12.389Z","modified":"2022-05-04T16:15:56.781Z","0.1.1":"2020-05-01T17:42:34.019Z","0.2.0":"2020-09-01T11:22:56.515Z"},"maintainers":[{"name":"qix","email":"i.am.qix@gmail.com"}],"description":"Zero-dependency (req,res) handler callback agent for use in client requests","homepage":"https://github.com/qix-/handler-agent#readme","keywords":["http","agent","server","api","tests","testing","tester","handler","rest","endpoint"],"repository":{"type":"git","url":"git+https://github.com/qix-/handler-agent.git"},"author":{"name":"Josh Junon","email":"josh@junon.me"},"bugs":{"url":"https://github.com/qix-/handler-agent/issues"},"license":"MIT","readme":"# `handler-agent`\n\n`handler-agent` creates a connection `http.Agent` usable by most HTTP clients that\nexecutes an HTTP handler (`function (req, res) { res.end('hi') }`) instead of\ncreating a network connection.\n\nThe returned agent can be used by `http.request()`, [`got`](https://npmjs.org/package/got),\nand most other Node.js HTTP clients that support the use of `http.Agent`s.\n\nThis is primarily useful for testing HTTP APIs without touching the network.\n\n## Usage\n\n```console\nnpm install --save handler-agent\n```\n\n```javascript\nconst handlerAgent = require('handler-agent');\n\nconst myHttpHandler = (req, res) => {\n\tif (req.url === '/' && req.method === 'GET') {\n\t\tres.writeHead(200);\n\t\tres.end('Hello, world!');\n\t} else {\n\t\tres.writeHead(404);\n\t\tres.end('Not Found');\n\t}\n};\n\nconst agent = handlerAgent(myHttpHandler);\n\nconst got = require('got').extend({\n\tagent: {\n\t\thttp: agent,\n\t\thttps: agent\n\t}\n});\n\ngot.get('http://localhost/')\n\t.then(response => {\n\t\tconsole.log('GET /: Got response:', response.body);\n\t});\n\ngot.post('http://localhost/foo')\n\t.catch(err => {\n\t\tconsole.error('POST /foo:', err.stack);\n\t});\n```\n\nOutput:\n\n```\nGET /: Got response: Hello, world!\nPOST /foo: HTTPError: Response code 404 (Not Found)\n    at PromisableRequest.<anonymous> (/src/qix-/handler-agent/node_modules/got/dist/source/as-promise/index.js:124:28)\n    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n```\n\n## But why?\n\nTesting an HTTP API in modern tooling seems to fall in two extremes; you either use\na bloated framework and desktop client, or you roll your own testing suite from scratch.\n\nFor me personally, I like rolling my own as I tend to put myself in unique scenarios that\ndon't quite fit into the nicely specified boxes the larger frameworks prescribe.\n\nThis module is a good middleground; I'm able to use `async`/`await` with my favorite HTTP\nrequest library (e.g. `got`) without having to start a real TCP server and deal with all of\nthe fragility that comes with it.\n\nUsing `handler-agent` prevents network issues such as re-used ports, latency (yes, really),\nmanaging port/host configuration, as well as removing the need for DNS lookups, modifying\n`/etc/hosts` just to test the `Host` header, etc.\n\n# License\n\nCopyright &copy; 2020 by Josh Junon.\nReleased under the [MIT License](LICENSE.txt).\n","readmeFilename":"README.md"}