2019.0.2 • Published 5 years ago

sws-request v2019.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

sws-request

npm version

  • Hybrid Node.js request library for our use cases (React.js client and server side rendering apps).

API Usages

  • request(url, options)

    We follow the minimal usages of request.js, by using the following keys in the request options.

    • Body: json (application/json), form (url-encoded form), formData (multipart/form).
    • Query parameters: qs.
    • Custom headers: headers.
const swsRequest = require('sws-request');

swsRequest.request(
    'http://localhost:8080/api/v1/post',
    {
        method: 'post',

        // body can be one within json, form, or formData
        json: {
            name: 'sws',
            key: 'value
        },
        
        form: {
            ...
        },

        formData: {
            ...
        },

        qs: {
            accessToken: 'auth'
        },

        headers: {
            "Authorization": "Bearer JWT"
        }
    }
).then(function (response) {
    // Check status, error if needed

    response.json().then(function (data) {
        return data;
    })
});

The Last Word

  • No need to install this package, you can import, modify it as a standalone file in your project. Any suggestions are welcome!

  • nghiaht (SWS - Soft World Studio).

2019.0.2

5 years ago

2019.0.1

6 years ago

2018.1.11

6 years ago

2018.1.10

6 years ago

2018.1.9

6 years ago

2018.1.8

6 years ago

2018.1.7

6 years ago

2018.1.6

6 years ago

2018.1.5

6 years ago

2018.1.4

6 years ago

2018.1.3

6 years ago

2018.1.2

6 years ago

2018.1.1

6 years ago

2018.1.0

6 years ago