Instant Utils
Client/server agnostic http request library.
Table of Contents
Installation
You can install this package using npm:
$ npm install instant-request
Usage
Here is a quick example to get you started:
ES Modules
;const request = 'https://example.com'; const test = async { const response = await request; // => https://example.com/api/records const json = await response; console;};
CommonJS Modules
var Request = Request;var request = 'https://example.com'; request // => https://example.com/api/records ;
API
Instantiation
Create an instance of the Request class.
Arguments
baseUrl (String)
: Base URL for all future requests.
options (Object) = {}
: Configuration object
Returns
instanceof Request
Example Usage
const request = 'https://example.com';
get
Make an HTTP GET request to the specified URI.
Arguments
uri (String)
: The URI to request, e.g /api/records
.
query (Object)
: The query object to append to the fully qualified URL, e.g { active: 1 }
=> https://example.com/api/records?active=1
.
Returns
Response
Example Usage
{ // https://example.com/api/countries const response = await request; const json = await response; return json;}
post
Make an HTTP POST request to the specified URI.
Arguments
uri (String)
: The URI to request, e.g /api/records
.
data (Object)
: The data to POST.
query (Object)
: The query object to append to the fully qualified URL, e.g { active: 1 }
=> https://example.com/api/records?active=1
.
Returns
Response
Example Usage
{ // https://example.com/api/countries const response = await request; const json = await response; return json;}
put
Make an HTTP PUT request to the specified URI.
Arguments
uri (String)
: The URI to request, e.g /api/records
.
data (Object)
: The data to PUT.
query (Object)
: The query object to append to the fully qualified URL, e.g { active: 1 }
=> https://example.com/api/records?active=1
.
Returns
Response
Example Usage
{ // https://example.com/api/countries const response = await request; const json = await response; return json;}
delete
Make an HTTP DELETE request to the specified URI.
Arguments
uri (String)
: The URI to request, e.g /api/records
.
query (Object)
: The query object to append to the fully qualified URL, e.g { active: 1 }
=> https://example.com/api/records?active=1
.
Returns
Response
Example Usage
{ // https://example.com/api/countries const response = await request; const json = await response; return json;}
Contributing
We'd greatly appreciate any contribution you make.