[{"data":1,"prerenderedAt":86},["Reactive",2],{"/samples/node/needle":3,"related:lSyg1S2MYC":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":8,"link":11,"body":12,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/samples/node/needle","node",false,"","Needle","Needle is a lightweight and flexible HTTP client for Node.js. It offers a simple and intuitive API for making HTTP requests and handling responses. Needle supports features like automatic decompression, streaming requests and responses, and multipart/form-data uploads.","Node","https://www.npmjs.com/package/needle",{"type":13,"children":14,"toc":52},"root",[15,30,43],{"type":16,"tag":17,"props":18,"children":19},"element","p",{},[20,28],{"type":16,"tag":21,"props":22,"children":25},"a",{"href":11,"rel":23},[24],"nofollow",[26],{"type":27,"value":8},"text",{"type":27,"value":29}," is a lightweight and flexible HTTP client for Node.js. It offers a simple and intuitive API for making HTTP requests and handling responses. Needle supports features like automatic decompression, streaming requests and responses, and multipart/form-data uploads.",{"type":16,"tag":31,"props":32,"children":37},"pre",{"className":33,"code":35,"language":36,"meta":7},[34],"language-javascript","const needle = require('needle');\nconst fs = require('fs');\n\nfunction convert(apiKey, params, endpoint='pdf') {\n    if (!['pdf', 'png', 'jpg', 'webp'].includes(endpoint)) {\n         throw new Error('Invalid endpoint');\n    } \n    \n    let options = {\n        headers: { 'X-API-Key': apiKey },\n        json: params,\n    }\n\n    return new Promise((resolve, reject) => {\n        needle.post(`https://api.pdfshift.io/v3/convert/${endpoint}`, params, options, function(err, resp) {\n            if (err) reject(err);\n            if ('filename' in params || 'webhook' in params) {\n                // Return in JSON in this case\n                resolve(JSON.parse(resp.body));\n            }\n            resolve(resp.body);\n        });\n    });\n}\n","javascript",[38],{"type":16,"tag":39,"props":40,"children":41},"code",{"__ignoreMap":7},[42],{"type":27,"value":35},{"type":16,"tag":31,"props":44,"children":47},{"className":45,"code":46,"language":36,"meta":7},[34],"const body = await convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'});\n\n// Write the response body to a local file\nfs.writeFile('result.pdf', body, 'binary')\n",[48],{"type":16,"tag":39,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":27,"value":46},{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:samples:node:needle.md","content","samples/node/needle.md","md",[61,65,69,73,74,78,82],{"_path":62,"language":10,"library":63,"_id":64},"/samples/node/axios","Axios","content:samples:node:axios.md",{"_path":66,"language":10,"library":67,"_id":68},"/samples/node/bent","Bent","content:samples:node:bent.md",{"_path":70,"language":10,"library":71,"_id":72},"/samples/node/got","Got","content:samples:node:got.md",{"_path":4,"language":10,"library":8,"_id":56},{"_path":75,"language":10,"library":76,"_id":77},"/samples/node/node-fetch","Node Fetch","content:samples:node:node-fetch.md",{"_path":79,"language":10,"library":80,"_id":81},"/samples/node/superagent","SuperAgent","content:samples:node:superagent.md",{"_path":83,"language":10,"library":84,"_id":85},"/samples/node/unfetch","Unfetch","content:samples:node:unfetch.md",1785426823252]