UNPKG

alia

Version:
24 lines (23 loc) 737 B
import https from 'node:https'; const baseUrl = `https://api.github.com/gists/`; function call(id, options, postData) { return new Promise((resolve, reject) => { const req = https.request(`${baseUrl}${id}`, options, (res) => { if (res.statusCode !== 200) { reject(new Error(res.statusMessage)); return; } res.setEncoding('utf8'); const body = []; res.on('data', (data) => body.push(data)); res.on('end', () => { resolve(JSON.parse(body.join(''))); }); }); if (postData) { req.write(postData); } req.end(); }); } export const request = { call };