You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{ request, parse }=require('request-half');// or import { request, parse } from 'request-half';consturl='some url here';// basic GET requestconstresponse=awaitrequest(url);// return value of request() would be http.IncomingMessageconsole.log(response.statusCode,response.headers);// send POST request only with the first argument as `options`constoptions={hostname: '127.0.0.1', port,path: '/',method: 'POST',body: '{ "test": "ok" }'};constresponse2=awaitrequest(options);// pass to parse() functionconstobject2=awaitparse('json',response);// curry parse functionconstobject=awaitrequest(url).then(parse('json'));// take response as bufferconstbuffer=awaitrequest(url).then(parse('buffer'));// parse as utf-8 textconsttext2=awaitrequest(newURL(url)).then(parse('utf8'));// default type is 'utf8'consttext=awaitrequest(newURL(url)).then(parse());// even without currying, default type is 'utf8'constresponse=awaitrequest(newURL(url));consttext2=awaitparse('utf8',response);consttext3=awaitparse(response);// POST Messageconstresult1=awaitrequest('http://example.com/article',{method: 'POST',headers: {'Content-type': 'application/json'},body: JSON.stringify({title: 'Hello, world',body: 'Use half to request, then else half to parse.'}),}).then(parse('json'));// GET Messageconstquerystring=require('querystring');consturl=`http://example.com/article?${querystring.stringify({title: 'Hello',orderBy: 'date'})}`;constresult2=awaitrequest(url).then(parse('json'));// HTTPS is also OK.constresult3=awaitrequest('https://example.com/article/1').then(parse('json'));