1.0.0 • Published 6 years ago
javascript-http-requester v1.0.0
javascript-http-requester
Description
Request building
Setter methods
setHeader
setUrl
setBody
HTTP request methods
The following methods represent HTTP request methods:
get
post
put
delete
patch
Request sending methods
The following asynchronous methods can send the request:
json
blob
arrayBuffer
text
xmlDocument
Each method name represents a response type.
Requirements
A modern web browser with support for:
- fetch
Install
$ npm install javascript-http-requester
Usage
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