just request it.
$ npm i just-request
import request from 'just-request';
request({
url: url,
method: 'get', // get, post, put, delete
data: {},
});
// shorthand
request(url); // method default to `get`
// with headers
request({
headers: {
'Content-Type': 'application/x-www-form-urlencoded', // `application/x-www-form-urlencoded` by default
// ...
},
});
.get(url[, data])
request('/api/posts');
// or
request().get('/api/posts')
// with data
request().get('/api/post', { id: 1 }); // it will request on `/api/post?id=1`.
.post(url[, data])
request().post('/api/posts', { content: 'content' })
.put(url[, data])
request().put('/api/posts', { id: 1 })
.delete(url[, data])
request().delete('/api/posts', { id: 1 })
.then(data => {})
request().get('/api/posts').then(data => {
// do something here...
});
.catch(error => {})
request().get('/api/posts').catch(error => {
// do something here...
});