{"id":17788,"library":"machinepack-http","title":"Machinepack HTTP","description":"machinepack-http provides a simple, `jQuery.get()`-like interface for sending HTTP requests, scraping webpages, and streaming data within Node.js and Sails.js applications. Currently at version 9.0.0, this library aims for immediate productivity in common cloud API interactions. It differentiates itself by offering robust error negotiation, distinguishing between network failures (e.g., offline, server down) and deliberate server errors (non-2xx status codes), and providing low-level streaming access to responses. The package is maintained by the Sails.js core team and follows the node-machine specification, acting as a higher-level wrapper around an underlying HTTP client. Its release cadence is tied to the Sails.js ecosystem, focusing on stability and integration.","status":"active","version":"9.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mikermcneil/machinepack-http","tags":["javascript","http","api","cloud","rest-api","curl","scraping","stream","request"],"install":[{"cmd":"npm install machinepack-http","lang":"bash","label":"npm"},{"cmd":"yarn add machinepack-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add machinepack-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core underlying HTTP client for making requests. Note: `request` is deprecated and unmaintained, posing a significant security risk for consumers of `machinepack-http`.","package":"request","optional":false}],"imports":[{"note":"Primarily designed for CommonJS `require`. While modern Node.js supports ESM, `machinepack-http`'s ecosystem typically uses CJS.","wrong":"import Http from 'machinepack-http';","symbol":"Http","correct":"const Http = require('machinepack-http');"},{"note":"Individual 'machines' are accessed as properties of the main `Http` object and must be executed with `.exec()`.","wrong":"import { send } from 'machinepack-http'; send(/* ... */);","symbol":"Http.send","correct":"const Http = require('machinepack-http');\nHttp.send(/* ... */).exec(/* ... */);"},{"note":"A convenient machine for GET requests. Always call `.exec()` to run a machine, providing named exit handlers.","wrong":"require('machinepack-http').get(/* ... */);","symbol":"Http.get","correct":"const Http = require('machinepack-http');\nHttp.get(/* ... */).exec(/* ... */);"}],"quickstart":{"code":"const Http = require('machinepack-http');\n\nconst TARGET_URL = process.env.TARGET_URL ?? 'https://example.com/api/data';\n\nHttp.get({\n  url: TARGET_URL,\n  data: { userId: 123 },\n  timeout: 5000,\n  headers: { 'User-Agent': 'Machinepack-HTTP-Example' }\n})\n.exec({\n  // Handle network-level errors (e.g., server down, DNS issues)\n  error: function (err) {\n    console.error('Network or unexpected error:', err.message);\n    // console.error(err); // Uncomment for full error stack\n  },\n  // Handle HTTP errors (non-2xx status codes) detected by the server\n  non2xx: function (response) {\n    console.warn(`Server responded with non-2xx status: ${response.statusCode}`);\n    console.warn('Response body:', response.body);\n  },\n  // Handle successful 2xx responses\n  success: function (response) {\n    console.log('Successfully fetched data!');\n    console.log(`Status Code: ${response.statusCode}`);\n    console.log('Response body:', JSON.parse(response.body));\n  }\n});","lang":"javascript","description":"Demonstrates making a GET request to a target URL, handling both network errors and non-2xx HTTP status code responses, and parsing a successful JSON response."},"warnings":[{"fix":"Consider migrating to a modern, maintained HTTP client such as `node-fetch`, `axios`, or the built-in Node.js `undici`. If `machinepack-http` is critical, monitor its updates for a transition away from `request`.","message":"machinepack-http v9.0.0 explicitly depends on the `request` package, which has been deprecated and is no longer maintained since 2019. The `request` package contains known security vulnerabilities and does not receive security updates. Relying on `machinepack-http` introduces these vulnerabilities into your application.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Familiarize yourself with the node-machine specification and the `.exec()` pattern. Always chain `.exec()` after calling a machine, providing handlers for all expected exit states.","message":"This package is built on the 'machinepack' specification, which uses a declarative, `.exec()`-based API. This differs significantly from Promise-based or callback-based HTTP clients. All 'machines' (like `get`, `post`, `send`) must be explicitly executed via a `.exec()` call, which then takes an object of exit handlers (e.g., `success`, `error`, `non2xx`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide distinct handlers for both the `error` and `non2xx` exits in your `.exec()` call to ensure robust error management.","message":"machinepack-http distinguishes between network errors (e.g., DNS resolution failure, connection refused) caught by the `error` exit, and non-2xx HTTP responses (e.g., 404, 500) caught by the `non2xx` exit. Developers commonly conflate these, leading to incomplete error handling.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate alternatives to `machinepack-http` or be prepared for potential future breaking changes if it undergoes a major rewrite to replace its `request` dependency.","message":"The underlying `request` library, which `machinepack-http` relies on, has been formally deprecated. While `machinepack-http` itself is maintained by the Sails.js core team, its fundamental dependency's deprecation indicates a significant risk and lack of future-proofing for this package.","severity":"deprecated","affected_versions":">=9.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `const Http = require('machinepack-http');` is present and that you are calling methods like `Http.get()` on the required object.","cause":"Attempting to call a 'machine' method without first requiring the `machinepack-http` module or incorrectly accessing the method.","error":"TypeError: Http.get is not a function"},{"fix":"Verify the target URL and port are correct and that the server is online and accessible. Check firewall rules on both client and server.","cause":"The target server actively refused the connection, usually because it's not running, or a firewall is blocking the connection. This error is caught by the `error` exit handler.","error":"Error: connect ECONNREFUSED"},{"fix":"Check the hostname for typos, ensure your network has access to a DNS server, or try accessing a different, known-good URL.","cause":"The hostname in the target URL could not be resolved to an IP address (DNS lookup failed). This error is caught by the `error` exit handler.","error":"Error: getaddrinfo ENOTFOUND"},{"fix":"Refer to the `node-machine.org` documentation for `machinepack-http` to see the list of available machines and their correct names. Ensure correct casing.","cause":"You are trying to call a method (machine) that does not exist on the `machinepack-http` module or you have a typo in the machine name.","error":"Error: Unknown machine: [machineName]"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}