[{"data":1,"prerenderedAt":296},["Reactive",2],{"/samples/node":3},[4,61,100,139,178,217,257],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"language":11,"library":9,"link":12,"body":13,"_type":56,"_id":57,"_source":58,"_file":59,"_extension":60},"/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":14,"children":15,"toc":53},"root",[16,31,44],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,29],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":9},"text",{"type":28,"value":30}," 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":17,"tag":32,"props":33,"children":38},"pre",{"className":34,"code":36,"language":37,"meta":8},[35],"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",[39],{"type":17,"tag":40,"props":41,"children":42},"code",{"__ignoreMap":8},[43],{"type":28,"value":36},{"type":17,"tag":32,"props":45,"children":48},{"className":46,"code":47,"language":37,"meta":8},[35],"let binary = await convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'});\nrequire('fs').writeFileSync('result.pdf', binary);\n",[49],{"type":17,"tag":40,"props":50,"children":51},{"__ignoreMap":8},[52],{"type":28,"value":47},{"title":8,"searchDepth":54,"depth":54,"links":55},2,[],"markdown","content:samples:node:axios.md","content","samples/node/axios.md","md",{"_path":62,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":63,"description":64,"language":11,"library":63,"link":65,"body":66,"_type":56,"_id":98,"_source":58,"_file":99,"_extension":60},"/samples/node/bent","Bent","Bent is a functional programming-style HTTP client for Node.js with support for async/await syntax. It offers a simple and expressive API for making HTTP requests and handling responses using functional programming concepts.","https://github.com/mikeal/bent",{"type":14,"children":67,"toc":96},[68,78,87],{"type":17,"tag":18,"props":69,"children":70},{},[71,76],{"type":17,"tag":22,"props":72,"children":74},{"href":65,"rel":73},[25],[75],{"type":28,"value":63},{"type":28,"value":77}," is a functional programming-style HTTP client for Node.js with support for async/await syntax. It offers a simple and expressive API for making HTTP requests and handling responses using functional programming concepts.",{"type":17,"tag":32,"props":79,"children":82},{"className":80,"code":81,"language":37,"meta":8},[35],"const bent = require('bent')\n\nconst convert = async (apiKey, params, endpoint='pdf') => {\n    if (!['pdf', 'png', 'jpg', 'webp'].includes(endpoint)) {\n        throw new Error('Invalid endpoint')\n    }\n\n    const post = bent(`https://api.pdfshift.io/v3/convert/${endpoint}`, 'POST', 'json', 200)\n\n    const response = await post('', params, {'X-API-Key': apiKey});\n    \n    if ('filename' in params || 'webhook' in params) {\n        return response;\n    }\n    \n    const getBuffer = bent('buffer');\n    const responseBuffer = await getBuffer(response.pdf.url);\n    return responseBuffer;\n}\n",[83],{"type":17,"tag":40,"props":84,"children":85},{"__ignoreMap":8},[86],{"type":28,"value":81},{"type":17,"tag":32,"props":88,"children":91},{"className":89,"code":90,"language":37,"meta":8},[35],"const fs = require('fs');\nconvert('sk_XXXXXXXXXXXXXX', {'source': 'https://en.wikipedia.org/wiki/REST'})\n    .then((binary) => {\n        fs.writeFile('result.pdf', binary, 'binary', (err) => {\n            if (err) throw err;\n        })\n    });\n",[92],{"type":17,"tag":40,"props":93,"children":94},{"__ignoreMap":8},[95],{"type":28,"value":90},{"title":8,"searchDepth":54,"depth":54,"links":97},[],"content:samples:node:bent.md","samples/node/bent.md",{"_path":101,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":102,"description":103,"language":11,"library":102,"link":104,"body":105,"_type":56,"_id":137,"_source":58,"_file":138,"_extension":60},"/samples/node/got","Got","Got is a lightweight and flexible HTTP client for Node.js. It provides a simple API for making HTTP requests with support for Promises and async/await syntax. Got focuses on performance, ease of use, and extensibility.","https://www.npmjs.com/package/got",{"type":14,"children":106,"toc":135},[107,117,126],{"type":17,"tag":18,"props":108,"children":109},{},[110,115],{"type":17,"tag":22,"props":111,"children":113},{"href":104,"rel":112},[25],[114],{"type":28,"value":102},{"type":28,"value":116}," is a lightweight and flexible HTTP client for Node.js. It provides a simple API for making HTTP requests with support for Promises and async/await syntax. Got focuses on performance, ease of use, and extensibility.",{"type":17,"tag":32,"props":118,"children":121},{"className":119,"code":120,"language":37,"meta":8},[35],"const got = require('got');\n\nasync function convert(apiKey, params, endpoint='pdf') {\n\n    if (!['pdf', 'png', 'jpg', 'webp'].includes(endpoint)){\n        throw new Error('Invalid endpoint');\n    }\n\n    const response = await got.post(`https://api.pdfshift.io/v3/convert/${endpoint}`, {\n        headers: { 'X-API-Key': apiKey },\n        json: params,\n        responseType: 'json'\n    });\n\n    if ('filename' in params || 'webhook' in params){\n        return response.body;\n    }\n\n    return response.rawBody;\n}\n",[122],{"type":17,"tag":40,"props":123,"children":124},{"__ignoreMap":8},[125],{"type":28,"value":120},{"type":17,"tag":32,"props":127,"children":130},{"className":128,"code":129,"language":37,"meta":8},[35],"(async () => {\n    const binary = await convert('sk_XXXXXXXXXXXXXX', { source: 'https://en.wikipedia.org/wiki/REST' });\n\n    require('fs').writeFileSync('result.pdf', binary);\n})()\n",[131],{"type":17,"tag":40,"props":132,"children":133},{"__ignoreMap":8},[134],{"type":28,"value":129},{"title":8,"searchDepth":54,"depth":54,"links":136},[],"content:samples:node:got.md","samples/node/got.md",{"_path":140,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":141,"description":142,"language":11,"library":141,"link":143,"body":144,"_type":56,"_id":176,"_source":58,"_file":177,"_extension":60},"/samples/node/needle","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.","https://www.npmjs.com/package/needle",{"type":14,"children":145,"toc":174},[146,156,165],{"type":17,"tag":18,"props":147,"children":148},{},[149,154],{"type":17,"tag":22,"props":150,"children":152},{"href":143,"rel":151},[25],[153],{"type":28,"value":141},{"type":28,"value":155}," 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":17,"tag":32,"props":157,"children":160},{"className":158,"code":159,"language":37,"meta":8},[35],"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",[161],{"type":17,"tag":40,"props":162,"children":163},{"__ignoreMap":8},[164],{"type":28,"value":159},{"type":17,"tag":32,"props":166,"children":169},{"className":167,"code":168,"language":37,"meta":8},[35],"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",[170],{"type":17,"tag":40,"props":171,"children":172},{"__ignoreMap":8},[173],{"type":28,"value":168},{"title":8,"searchDepth":54,"depth":54,"links":175},[],"content:samples:node:needle.md","samples/node/needle.md",{"_path":179,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":180,"description":181,"language":11,"library":180,"link":182,"body":183,"_type":56,"_id":215,"_source":58,"_file":216,"_extension":60},"/samples/node/node-fetch","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.","https://www.npmjs.com/package/node-fetch",{"type":14,"children":184,"toc":213},[185,195,204],{"type":17,"tag":18,"props":186,"children":187},{},[188,193],{"type":17,"tag":22,"props":189,"children":191},{"href":182,"rel":190},[25],[192],{"type":28,"value":180},{"type":28,"value":194}," 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":17,"tag":32,"props":196,"children":199},{"className":197,"code":198,"language":37,"meta":8},[35],"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",[200],{"type":17,"tag":40,"props":201,"children":202},{"__ignoreMap":8},[203],{"type":28,"value":198},{"type":17,"tag":32,"props":205,"children":208},{"className":206,"code":207,"language":37,"meta":8},[35],"convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'})\n    .then(buffer => {\n        require('fs').writeFile('result.pdf', buffer, () => {});\n    });\n",[209],{"type":17,"tag":40,"props":210,"children":211},{"__ignoreMap":8},[212],{"type":28,"value":207},{"title":8,"searchDepth":54,"depth":54,"links":214},[],"content:samples:node:node-fetch.md","samples/node/node-fetch.md",{"_path":218,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":219,"description":220,"language":11,"library":221,"link":222,"body":223,"_type":56,"_id":255,"_source":58,"_file":256,"_extension":60},"/samples/node/superagent","Superagent","SuperAgent is a feature-rich HTTP client for Node.js and the browser. It provides an intuitive API for making HTTP requests and handling responses. Superagent supports features like request chaining, form data encoding, and streaming responses.","SuperAgent","https://www.npmjs.com/package/superagent",{"type":14,"children":224,"toc":253},[225,235,244],{"type":17,"tag":18,"props":226,"children":227},{},[228,233],{"type":17,"tag":22,"props":229,"children":231},{"href":222,"rel":230},[25],[232],{"type":28,"value":221},{"type":28,"value":234}," is a feature-rich HTTP client for Node.js and the browser. It provides an intuitive API for making HTTP requests and handling responses. Superagent supports features like request chaining, form data encoding, and streaming responses.",{"type":17,"tag":32,"props":236,"children":239},{"className":237,"code":238,"language":37,"meta":8},[35],"const superagent = require('superagent');\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    let response = await superagent\n        .post(`https://api.pdfshift.io/v3/convert/${endpoint}`)\n        .set('X-API-Key', api_key)\n        .send(params);\n        \n    if ('filename' in params || 'webhook' in params) {\n        // Return in JSON in that case\n        return response.body;\n    }\n\n    // Returns the binary content\n    return response.body;\n}\n",[240],{"type":17,"tag":40,"props":241,"children":242},{"__ignoreMap":8},[243],{"type":28,"value":238},{"type":17,"tag":32,"props":245,"children":248},{"className":246,"code":247,"language":37,"meta":8},[35],"const binary = await convert('sk_XXXXXXXXXXXXXX', {source: 'https://en.wikipedia.org/wiki/REST'})\nrequire('fs').writeFileSync('result.pdf', binary);\n",[249],{"type":17,"tag":40,"props":250,"children":251},{"__ignoreMap":8},[252],{"type":28,"value":247},{"title":8,"searchDepth":54,"depth":54,"links":254},[],"content:samples:node:superagent.md","samples/node/superagent.md",{"_path":258,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":259,"description":260,"language":11,"library":259,"link":261,"body":262,"_type":56,"_id":294,"_source":58,"_file":295,"_extension":60},"/samples/node/unfetch","Unfetch","Unfetch is a lightweight and minimalistic HTTP client for Node.js and the browser. It offers a simple API for making HTTP requests and handling responses with minimal overhead. Unfetch focuses on simplicity, performance, and ease of use.","https://www.npmjs.com/package/unfetch",{"type":14,"children":263,"toc":292},[264,274,283],{"type":17,"tag":18,"props":265,"children":266},{},[267,272],{"type":17,"tag":22,"props":268,"children":270},{"href":261,"rel":269},[25],[271],{"type":28,"value":259},{"type":28,"value":273}," is a lightweight and minimalistic HTTP client for Node.js and the browser. It offers a simple API for making HTTP requests and handling responses with minimal overhead. Unfetch focuses on simplicity, performance, and ease of use.",{"type":17,"tag":32,"props":275,"children":278},{"className":276,"code":277,"language":37,"meta":8},[35],"const fetch = require('unfetch')\n\nasync function convert(api_key, params, endpoint = 'pdf') {\n    const validEndpoints = ['pdf', 'png', 'jpg', 'webp'];\n    if (!validEndpoints.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            'Content-Type': 'application/json',\n            'X-API-Key': api_key\n        },\n        body: JSON.stringify(params)\n    });\n\n    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);\n\n    if ('filename' in params || 'webhook' in params) {\n        return await response.json();\n    }\n\n    return Buffer.from(await response.blob(), 'utf8');\n}\n",[279],{"type":17,"tag":40,"props":280,"children":281},{"__ignoreMap":8},[282],{"type":28,"value":277},{"type":17,"tag":32,"props":284,"children":287},{"className":285,"code":286,"language":37,"meta":8},[35],"const binary = await convert('sk_XXXXXXXXXXXXXX', { 'source': 'https://en.wikipedia.org/wiki/REST' });\nrequire('fs').promises.writeFile('result.pdf', binary);\n",[288],{"type":17,"tag":40,"props":289,"children":290},{"__ignoreMap":8},[291],{"type":28,"value":286},{"title":8,"searchDepth":54,"depth":54,"links":293},[],"content:samples:node:unfetch.md","samples/node/unfetch.md",1785426821573]