@to1source/request
v0.9.4
Published
Super simple http package using native http.request to replace the popular request package for our own use
Downloads
7
Readme
@to1source/request
Description
Super simple http package to replace the popular request npm for our own use
This is node.js ONLY package
Installation
$ npm i @to1source/request
Instructions
The easiest way:
const request = require('@to1source/request')
// default it's a get
request('http://example.com')
.then(({result, res}) => {
// do your thing
})
.catch(err => {
// when statusCode !== 200
// we are young, so we don't know how to handle 301 yet
// it will be in the future release
})
Using the main request
will return a promise that resolve
- result: whatever the server respond with, and we will try to parse it as JSON
- res: the original respond object, you can further process it
Or you need to do post?
request('http://example.com', {method: 'post', formData: {id: 1}})
.then(({result, res}) => {
// do your thing
})
.catch(err => {
})
Short hands methods
If you don't care much about the processing, and just want a quick result. We recommend you to use the short methods intead.
Everthing short hand will only return the server respond result;
this is different from using just the request
call.
request.get
const request = require('@to1source/request')
request.get('http://example.com')
.then(result => {
// do your thing
})
request.post
request.post('http://example.com', {id: 1})
.then(result => {
// do your thing
})
request.form
request.form('http://example.com', {id: 1})
.then(result => {
// do your thing
})
This method will set the header to multipart/form-data
@TODO file upload
request.jsonql
This is a special method purposely develop for our own jsonql framework
To include this one need to use a different path
const request = require('@to1source/request/jsonql')
request.jsonql('http://example.com', payload, config)
.then(result => {
// do our thing
})
Since this is a very special method develop as another part of our framework component, we are not going to go into detail here (it's much more complex that it looks). If you are interested. You can check out our jsonql website.
Contribution
- Fork the repository
- Create Feat_xxx branch
- Commit your code
- Create Pull Request
Gitee Feature
- You can use Readme_XXX.md to support different languages, such as Readme_en.md, Readme_zh.md
- Gitee blog blog.gitee.com
- Explore open source project https://gitee.com/explore
- The most valuable open source project GVP
- The manual of Gitee https://gitee.com/help
- The most popular members https://gitee.com/gitee-stars/