{"library":"stream-http","title":"Node.js HTTP API for Browsers","type":"library","description":"stream-http is a JavaScript library designed to provide a browser-compatible implementation of Node.js's native `http` module. Its primary goal is to replicate the Node.js HTTP client API and behavior as closely as possible within the constraints of web browsers, making it suitable for projects that need consistent HTTP request handling across Node.js and browser environments. The package is currently at version 3.2.0 and appears to be actively maintained, indicated by recent feature additions and ongoing support for modern browser capabilities. A key differentiator is its emphasis on streaming, delivering data to the caller before the request fully completes. It supports true streaming with backpressure in Chrome >= 58 via `fetch` and `WritableStream`, true streaming in Chrome >= 43 (via `fetch`) and Firefox >= 9 (via `moz-chunked-arraybuffer`), and pseudo-streaming in other supported browsers where the full response is held in memory but available early. It aims to replace `http-browserify`. It also provides additional browser-specific features like `message.url` for redirects and `options.withCredentials` for CORS requests.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install stream-http"],"cli":null},"imports":["import http from 'stream-http'","const http = require('stream-http')","import http from 'stream-http'; const { METHODS, STATUS_CODES } = http;"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/jhiesey/stream-http","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stream-http","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import http from 'stream-http';\n\n// Example: Fetch data from a public API\nconst options = {\n  host: 'jsonplaceholder.typicode.com',\n  path: '/posts/1',\n  method: 'GET'\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n\n  let data = '';\n  res.on('data', (chunk) => {\n    data += chunk;\n  });\n\n  res.on('end', () => {\n    console.log('No more data in response.');\n    try {\n      const parsedData = JSON.parse(data);\n      console.log('Response body:', parsedData);\n    } catch (e) {\n      console.error('Failed to parse JSON:', e);\n      console.log('Raw response body:', data);\n    }\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\nreq.end();","lang":"javascript","description":"This quickstart demonstrates how to make a GET request using the `http.request` method, similar to Node.js. It shows how to set request options, handle the response stream, and process incoming data chunks until the request ends, including error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}