[{"data":1,"prerenderedAt":86},["Reactive",2],{"/samples/node/node-fetch":3,"related:zoD8iwS6WS":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/node-fetch","node",false,"","Node Fetch","Node Fetch is a native implementation of the fetch() API for making HTTP requests in Node.js. It provides a modern and standards-compliant API for fetching resources over the network. Node Fetch supports Promises and async/await syntax, making it easy to work with asynchronous code.","Node","https://www.npmjs.com/package/node-fetch",{"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 native implementation of the fetch() API for making HTTP requests in Node.js. It provides a modern and standards-compliant API for fetching resources over the network. Node Fetch supports Promises and async/await syntax, making it easy to work with asynchronous code.",{"type":16,"tag":31,"props":32,"children":37},"pre",{"className":33,"code":35,"language":36,"meta":7},[34],"language-javascript","const fetch = require('node-fetch');\n\nasync function convert(api_key, params, endpoint='pdf') {\n\n    if (!['pdf', 'png', 'jpg', 'webp'].includes(endpoint)) {\n        throw new Error('Invalid endpoint');\n    }\n    \n    const response = await fetch(`https://api.pdfshift.io/v3/convert/${endpoint}`, {\n        method: 'post',\n        headers: {\n            'X-API-Key': api_key,\n            'Content-Type': 'application/json'\n        },\n        body: JSON.stringify(params)\n    });\n\n    if (!response.ok) {\n        throw new Error(`HTTP error! status: ${response.status}`);\n    }\n    \n    if ('filename' in params || 'webhook' in params) {\n        //Return in JSON in this case\n        return response.json();\n    }\n    \n    //Returns the bytes\n    return response.buffer();\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],"convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'})\n    .then(buffer => {\n        require('fs').writeFile('result.pdf', buffer, () => {});\n    });\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:node-fetch.md","content","samples/node/node-fetch.md","md",[61,65,69,73,77,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":74,"language":10,"library":75,"_id":76},"/samples/node/needle","Needle","content:samples:node:needle.md",{"_path":4,"language":10,"library":8,"_id":56},{"_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",1785426823255]