1.0.0 • Published 6 years ago
javascript-http-requester v1.0.0
javascript-http-requester
Description
Request building
Setter methods
setHeadersetUrlsetBody
HTTP request methods
The following methods represent HTTP request methods:
getpostputdeletepatch
Request sending methods
The following asynchronous methods can send the request:
jsonblobarrayBuffertextxmlDocument
Each method name represents a response type.
Requirements
A modern web browser with support for:
- fetch
Install
$ npm install javascript-http-requesterUsage
Common requests
import { HttpRequester, NoAuthAjaxAdapter } from 'javascript-http-requester';
async function request() {
const xmlDocument = await new HttpRequester(new NoAuthAjaxAdapter())
.setUrl('path/to/xml')
.get()
.xmlDocument();
console.log(xmlDocument);
}
request();Authorized requests
The authorization provider must be passed to the AuthAjaxAdapter class constructor to create an authorized request.
Authorization provider must contain asynchronous method getAccessToken that resolves with a Bearer access token.
import { HttpRequester, AuthAjaxAdapter } from 'javascript-http-requester';
async function request() {
const object = await new HttpRequester(new AuthAjaxAdapter(yourAuthProvider))
.setUrl('path/to/data')
.get()
.json();
console.log(object);
}
request();1.0.0
6 years ago