@cqmbr/request

http request based on fetch api

Stats

StarsIssuesVersionUpdatedCreatedSize
@cqmbr/request
101.2.23 years ago3 years agoMinified + gzip package size for @cqmbr/request in KB

Readme

request

http request based on fetch api

node npm license Build Status Standard - JavaScript Style Guide Coverage Status

Installation

npm i @cqmbr/request

Use

import Request from '@cqmbr/request'

const request = new Request(options)

API

new Request(options)

create a request instance

  • options:
    • options.baseURL: base url
    • options.headers: default headers
    • options.beforeRequest: will be called before request, you can handle with request config and return a new config, support Promise
    • options.afterRequest: will be called after request, you can handle with response and return it, support Promise

request.request(url, requestOptions)

basic http request

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: string

    resource url, it will be automatically added after baseURL if you set it in constructor, support params

  • query: object

    query params, it will be automatically added after url

  • body: object

    request body, if request method is GET, it's same as query

  • params: object

    url params will be automatically replaced based on params, such as /{id} will be replaced by params.id

  • headers: object

    request headers

TODO

  • unit test
  • flow support

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.