flexible-axios

1.0.1 • Public • Published

flexible-axios

A library of http request based on axios that supports the browser and node.js.

Install

Using unpkg CDN

<script src="https://unpkg.com/flexible-axios/dist/index.min.js"></script>

Using npm

npm install flexible-axios --save

Usage

CommonJS usage

const flexibleAxios = require('flexible-axios')

Method

Get request

flexibleAxios.get(url, config)

  • {String} url => request url.(required)
  • {Object} config => request config.(optional). Including headers|timeout, etc. Default value is null, further information can be queried related document https://axios-http.com/docs/req_config

Post request

flexibleAxios.post(url, data, config)

  • {String} url => request url.(required)
  • {Object} data => request data.(optional). Default value is null.
  • {Object} config => request config.(optional). Including headers|timeout, etc. Default value is null, further information can be queried related document https://axios-http.com/docs/req_config

Notice

Post request set default Content-Type is 'application/json'. If you want to rewrite Content-Type, let's see it:

flexibleAxios.post(url, data, {
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
})

Upload file Method(Specail instance of post method)

flexibleAxios.uploadFile(url, formData)

  • {String} url => request url.(required)
  • {Object} formData => FormData object, support binary file and other key-value data. You can use native FormData in the browser environment, use form-data module in nodejs environment.(required)

Set http header key

flexibleAxios.setHeader(key, value)

  • {String} key => key name.(required)
  • {String} value => value.(required)

License

flexible-axios is MIT licensed.

Dependents (4)

Package Sidebar

Install

npm i flexible-axios

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

24.1 kB

Total Files

8

Last publish

Collaborators

  • amoydreamer