1.3.0 • Published 7 years ago
@cqlinkoff/request v1.3.0
request
http request based on
fetchapi
Installation
npm i @cqlinkoff/requestUse
import Request from '@cqlinkoff/request'
const request = new Request(options)API
new Request(options)
create a request instance
options:options.baseURL: base urloptions.headers: default headersoptions.beforeRequest: will be called before request, you can handle withrequestconfig and return a new config, supportPromiseoptions.afterRequest: will be called after request, you can handle withresponseand return it, supportPromise
request.request(url, requestOptions)
basic http request
url:stringorobject, if it'sobject, it will be treated asrequestOptions, seerequestOptionsrequestOptions: seerequestOptions
request.get(url, requestOptions): Promise<any>
request use
GET
request.post(url, requestOptions): Promise<any>
request use
POST
request.put(url, requestOptions): Promise<any>
request use
PUT
request.patch(url, requestOptions): Promise<any>
request use
PATCH
request.del(url, requestOptions): Promise<any>
request use
DELETE
requestOptions
request config
url:stringresource url, it will be automatically added after
baseURLif you set it in constructor, supportparamsquery:objectquery params, it will be automatically added after
urlbody:objectrequest body, if request method is
GET, it's same asqueryparams:objecturl params will be automatically replaced based on
params, such as/{id}will be replaced byparams.idheaders:objectrequest headers
TODO
- unit test
- flow support