# @to1source_request **Repository Path**: to1source/request ## Basic Information - **Project Name**: @to1source_request - **Description**: Super simple http package to replace the popular request npm for our own use - **Primary Language**: JavaScript - **License**: Unlicense - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-01 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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 ```sh $ npm i @to1source/request ``` ## Instructions The easiest way: ```js 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? ```js 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 ```js const request = require('@to1source/request') request.get('http://example.com') .then(result => { // do your thing }) ``` #### request.post ```js request.post('http://example.com', {id: 1}) .then(result => { // do your thing }) ``` #### request.form ```js 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](https://jsonql.org) framework To include this one need to use a different path ```js 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](https://jsonql.org) website. --- #### Contribution 1. Fork the repository 2. Create Feat_xxx branch 3. Commit your code 4. Create Pull Request #### Gitee Feature 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md 2. Gitee blog [blog.gitee.com](https://blog.gitee.com) 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) --- [TO1SOURCE](https://to1source.cn) [NEWBRAN LTD](https://newbran.ch)