{"library":"needle","title":"Needle HTTP Client","description":"Needle is a lightweight and performant HTTP client for Node.js, designed for various HTTP/HTTPS requests, including API interactions, file uploads, and data streaming. The current stable version is 3.5.0, and the project maintains a moderate release cadence, focusing on stability, bug fixes, and incremental feature enhancements, with major versions occurring less frequently. Key differentiators include its minimal dependency footprint, built-in support for streaming gzip, deflate, and brotli decompression (Node 10+), and automatic JSON/XML parsing. Its API is flexible, supporting traditional callbacks, modern Promises, and direct stream piping, allowing developers to choose the paradigm best suited for their application. Needle also handles essential features like Basic & Digest authentication, multipart form-data uploads, and HTTP proxy forwarding, positioning itself as an efficient alternative for quick and reliable HTTP operations in Node.js environments.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install needle"],"cli":null},"imports":["import needle from 'needle';","import needle from 'needle';\nneedle.get('url', callback);","import needle from 'needle';\nneedle.post('url', data, options, callback);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import needle from 'needle';\nimport https from 'https'; // Required for AgentOptions if using self-signed certs\n\nconst agent = new https.Agent({\n  rejectUnauthorized: process.env.NODE_ENV === 'production' // Example TLS option\n});\n\nconst data = {\n  username: 'testuser',\n  password: process.env.TEST_PASSWORD ?? 'securepassword123'\n};\n\nneedle('post', 'https://httpbin.org/post', data, { json: true, agent: agent })\n  .then(response => {\n    if (response.statusCode === 200) {\n      console.log('Request successful:', response.body.json);\n    } else {\n      console.error('Request failed with status:', response.statusCode);\n    }\n  })\n  .catch(err => {\n    console.error('An error occurred during POST request:', err.message);\n  });\n\n// Example using callback style for a GET request\nneedle.get('https://httpbin.org/get', { agent: agent }, (error, response) => {\n  if (error) {\n    console.error('GET request error:', error.message);\n    return;\n  }\n  if (response.statusCode === 200) {\n    console.log('GET successful:', response.body.json);\n  } else {\n    console.error('GET failed with status:', response.statusCode);\n  }\n});","lang":"typescript","description":"Demonstrates a Promise-based POST request for JSON data and a callback-based GET request, including basic error handling and HTTPS agent options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}