A HTTP request abstract library, use other http request libraries in one way. Isomorphic request to work in Node or in the browser. For example React isomorphism, the same code for the server and the browser.
- Different libraries use different syntax, the replacement library will lead to a large number of changes
- The browser and the server can use the same code for different libraries. For example: the browser with reqwest, the server with request. Or both the browser and the server are using fetch.
npm install hahoorequest --save
Select the library you want to use
import request from 'hahoorequest/lib/fetch';
import request from 'hahoorequest/lib/fetch-request';
import request from 'hahoorequest/lib/reqwest-fetch';
import request from 'hahoorequest/lib/reqwest-request';
import request from 'hahoorequest/lib/superagent';
import request from 'hahoorequest/lib/superagent-fetch';
import request from 'hahoorequest/lib/superagent-request';
import request from 'hahoorequest/lib/whatwg-fetch';
import request from 'hahoorequest/lib/reqwest';
import request from 'hahoorequest/lib/superagent';
import request from 'hahoorequest/lib/node-fetch';
import request from 'hahoorequest/lib/node-request';
Return Promises
request({
url: 'https://raw.githubusercontent.com/hahoocn/hahoorequest/master/test/test.json',
method: 'GET',
type: 'json'
})
.then((res) => {
console.log(res.body);
});
url
a fully qualified urimethod
http method (default:GET
)headers
http headersbody
entity body forPATCH
,POST
andPUT
requests. Must be a queryString
orJSON
objecttype
a string enum.html
,xml
,json
,form
,png
... (default:json
)qs
object containing querystring values to be appended to the urlcredentials
Sending cookies. fetch set credentials option. if credentials is not undefined, reqwest and superagent will addwithCredentials = true
response.body
Content of responseresponse.status
http status code
response.errcode
Code of errorsresponse.errmsg
Content of errors