{"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install machinepack-http"],"cli":null},"imports":["const Http = require('machinepack-http');","const Http = require('machinepack-http');\nHttp.send(/* ... */).exec(/* ... */);","const Http = require('machinepack-http');\nHttp.get(/* ... */).exec(/* ... */);"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}