{"library":"responselike","title":"Mock HTTP Response Stream","description":"Responselike provides a streamable object designed to mimic a Node.js HTTP response stream (`http.IncomingMessage`). This utility is primarily used for mocking HTTP responses in testing scenarios or for reformatting cached data to be consumed by code expecting a standard HTTP response. The current stable version is 4.0.2. The package is actively maintained by Sindre Sorhus, with releases typically occurring as needed for bug fixes or Node.js version updates, as seen with the recent v4.0.0 and v4.0.1/v4.0.2 updates. Its key differentiator is its focus on accurately replicating the streamable nature and properties of a native HTTP response, making it suitable for integrations where stream-based consumption is expected, unlike simpler object mocks.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install responselike"],"cli":null},"imports":["import Response from 'responselike';","import type { ResponseOptions } from 'responselike';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Response from 'responselike';\nimport { Writable } from 'stream';\n\nclass TestStream extends Writable {\n  _write(chunk, encoding, callback) {\n    console.log(chunk.toString());\n    callback();\n  }\n}\n\nconst response = new Response({\n\tstatusCode: 200,\n\theaders: {\n\t\t'content-type': 'text/plain',\n\t\t'x-custom-header': 'value'\n\t},\n\tbody: Buffer.from('Hello, World! This is a mocked response body.'),\n\turl: 'https://example.com/api/data'\n});\n\nconsole.log(`Status Code: ${response.statusCode}`);\nconsole.log(`URL: ${response.url}`);\nconsole.log('Headers:', response.headers);\n\nconst testOutput = new TestStream();\nconsole.log('\\nStreaming body content:');\nresponse.pipe(testOutput);\n","lang":"typescript","description":"Demonstrates creating a mock HTTP response, accessing its properties, and piping its body as a stream.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}