1.0.1 • Published 5 years ago
awire v1.0.1
Description:
awire is a promise based http request framework.
Installing:
npm install awire
Importing:
import awire from 'awire'
Example:
1. using the GET request:
awire.get('http://127.0.0.1:3000').then( res => {
//do something with the response(res).
}).catch( err => {
//do something with the error(err).
}).finally( () => {
//do something when the request is finished.
})
2. using the POST request:
awire.post('http://127.0.0.1:3000',{ name: 'Eli' }).then( res => {
//do something with the response(res).
}).catch( err => {
//do something with the error(err).
}).finally( () => {
//do something when the request is finished.
})
//it only supports four methods(GET,POST,PUT,DELETE) for now.
3. using the config option:
awire.post(url,data,config).then( res => {
//do something with the response(res).
}).catch( err => {
//do something with the error(err).
}).finally( () => {
//do something when the request is finished.
})
awire.post('http://127.0.0.1:3000',{ name: 'Eli' },{
headers: {
'Content-Type': 'text/plain'
}
}).then( res => {
//do something with the response(res).
}).catch( err => {
//do something with the error(err).
}).finally( () => {
//do something when the request is finished.
})
//it only support headers config for now.
4. using the baseURL property:
awire.baseURL = "http://127.0.0.1:3000"
awire.get('/').then( res => {})
//is equal when awire.baseURL = '' (by default)
awire.get('http://127.0.0.1:3000/').then( res => {})