request
Use the built-in callback-style HTTP adapter.
js
request(input, options?, callback)Arguments
| Argument | Type | Meaning |
|---|---|---|
input | string | object | URL string or options object. |
options | object | Optional url/uri, method, headers, string body, json, form, qs and timeout (milliseconds). |
callback | function | (error, response, body). Response has statusCode, lowercase headers, body and url. |
Returns
Request handle with abort(). Errors may also throw before submission.
Example
js
const request = require("request");
request("https://example.com", {timeout: 5000}, (error, response, body) => {
if (error) throw error;
if (response.statusCode >= 400) throw new Error("HTTP " + response.statusCode);
console.log(body);
});Notes
This is an ApplesauceOS adapter. json:true parses a JSON response and can serialize an object body; form and qs accept scalar values. No streams, multipart, proxy or cookie-jar support. Also available as require("applesauceos/http").request. request.implementation identifies the built-in adapter; it is metadata, not an executable function.