@0y0/reaxios
is a easy-to-use HTTP client based on axios for the browser and NodeJS.
npm install @0y0/reaxios --save
import Reaxios from '@0y0/reaxios'
As an alternative to using npm, you can use @0y0/reaxios
as a <script>
tag from a CDN.
<script src="https://unpkg.com/@0y0/reaxios/dist/index.min.js"></script>
<script>Reaxios.get('http://...')</script>
Reaxios.get('/api')
Reaxios.post('/api')
Reaxios.put('/api')
Reaxios.delete('/api')
// headers: { foo: 'bar' }
Reaxios.get('/api').header('foo', 'bar')
// headers: { Authorization: 'bar' }
Reaxios.get('/api').auth('bar')
// headers: { Authorization: 'Bearer token' }
Reaxios.get('/api').bearer('token')
// headers: { foo1: 'bar1', Authorization: 'token' }
Reaxios.get('/api')
.header('foo1', 'bar1')
.header('foo2', undefined)
.auth('token')
// url: /api/?foo=bar
Reaxios.get('/api').param('foo', 'bar')
// url: /api/?foo2=bar2
Reaxios.get('/api').param('foo1', undefined).param('foo2', 'bar2')
// url: /api/?foo1=bar1&foo2=bar2
Reaxios.get('/api').params({ foo1: 'bar1', foo2: 'bar2' })
Reaxios.post('/api').body('content')
// Content-Type: application/json
Reaxios.post('/api').body({ foo: 'bar' })
// Content-Type: multipart/form-data
Reaxios.post('/api')
.header('Content-Type', 'multipart/form-data')
.body(new FormData())
// Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Reaxios.post('/api')
.header('Content-Type', 'application/x-www-form-urlencoded')
.body(new URLSearchParams())
Reaxios.post('/api')
.body('data')
// send `{ data: 'data' }` to server
.transformRequest(data => ({ data }))
// receive `{ data: 'data' }` from server and resolve promise with `'data'`
.transformResponse(({ data }) => data)
const promsie = async () => await Reaxios.post('/api').body('content')
promise.cancel()