[{"data":1,"prerenderedAt":86},["Reactive",2],{"/samples/node/axios":3,"related:diWc3ehb5F":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/axios","node",false,"","Axios","Axios is a popular Promise-based HTTP client for Node.js and the browser. It provides an easy-to-use API for making HTTP requests and handling responses asynchronously. Axios supports features like request and response interceptors, automatic JSON data transformation, and request cancellation.","Node","https://axios-http.com/",{"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 popular Promise-based HTTP client for Node.js and the browser. It provides an easy-to-use API for making HTTP requests and handling responses asynchronously. Axios supports features like request and response interceptors, automatic JSON data transformation, and request cancellation.",{"type":16,"tag":31,"props":32,"children":37},"pre",{"className":33,"code":35,"language":36,"meta":7},[34],"language-javascript","const axios = require('axios');\n\nasync function convert(api_key, params, endpoint = 'pdf') {\n    if (!['pdf', 'png', 'jpg', 'webp'].includes(endpoint)) {\n        throw new Error('Invalid endpoint');\n    }\n\n    try {\n        const response = await axios.post(`https://api.pdfshift.io/v3/convert/${endpoint}`, params, {\n            headers: { 'X-API-Key': api_key }\n        });\n\n        if (params.filename || params.webhook) {\n            // Return JSON in this case\n            return response.data;\n        }\n\n        // Returns the binary data\n        return response.data;\n\n    } catch (error) {\n        console.error(error);\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],"let binary = await convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'});\nrequire('fs').writeFileSync('result.pdf', 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:axios.md","content","samples/node/axios.md","md",[61,62,66,70,74,78,82],{"_path":4,"language":10,"library":8,"_id":56},{"_path":63,"language":10,"library":64,"_id":65},"/samples/node/bent","Bent","content:samples:node:bent.md",{"_path":67,"language":10,"library":68,"_id":69},"/samples/node/got","Got","content:samples:node:got.md",{"_path":71,"language":10,"library":72,"_id":73},"/samples/node/needle","Needle","content:samples:node:needle.md",{"_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",1785426823225]