universal-request
Used to initiate a network request
Last updated 5 years ago by balloonzzq .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install universal-request 
SYNC missed versions from official npm registry.

universal-request npm

Used to initiate a network request

Install

$ npm install universal-request --save

Usage

import request from 'universal-request';

request({
  url: 'https://alibaba.github.io/rax/',
  method: 'POST',
  data: {
    from: 'Rax',
  },
  dataType: 'json'
}).then(response => {})
  .catch(error => {});

Methods

request(options)

Supported

browser weex miniApp WeChatMiniProgram

Arguments

Property Type Description required Default
options object true -
opthons.url string Required,the request url true -
opthons.headers object The request headers false {
  'Content-Type': 'application/json'
}
options.method string Values:GET/POST/PUT/DELETE/PATCH/HEAD,mini app only support GET/POST false GET
options.data object
- GET or POST set headers['content-Type'] is equal to application/x-www-form-urlencoded data will apply to URL
- In other cases, the data will be converted to a JSON string as request body to the server.
false -
options.timeout number timeout false 20000 (ms)
options.dataType string Set return data type, json or text, If the conversion fails, returns as it is false json

Return

Success return:Promise<Response>

Property Type Description
response object -
response.data string The data returned by the request is converted according to the type declared in the dataType. If the conversion fails, it is returned as it is
response.headers object Response headers ,JSONP request has no value
response.status number Response status,JSONP request has no value

Fail return:

Property Type Description
error object -
error.code number Error code
error.message string Error message

error code:

code message Description
0 Reason of failure Request failed except for the listed below
1 Request timeout timeout
2 Request not support this platform not support this platform

Current Tags

  • 2.2.2-0                                ...           beta (4 years ago)
  • 2.2.2                                ...           latest (3 years ago)

14 Versions

  • 2.2.2                                ...           3 years ago
  • 2.2.2-0                                ...           4 years ago
  • 2.2.1                                ...           4 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 2.0.0-0                                ...           5 years ago
  • 1.0.3-beta.1                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 1.0.0-beta.2                                ...           6 years ago
  • 1.0.0-beta.1                                ...           6 years ago
Downloads
Total 12
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE