ngxfetch
v1.0.5
Published
Angular like http fetch wrapper
Downloads
4
Readme
ngxfetch
Installation
npm install --save ngxfetch
Usage
import { request } from 'ngxfetch'
request.get('http://example.com')
.then(response => console.log(response)) // response as JSON
.catch(error => console.log(error)) // error object { status, message }
import NGXFetch from 'ngxfetch'
const request = new NGXFetch(options)
request.get('http://example.com')
.then(response => console.log(response)) // response as JSON
.catch(error => console.log(error)) // error object { status, message }
Methods
request.get(url, options?)
request.delete(url, options?)
request.post(url, data, options?)
request.put(url, data, options?)
request.patch(url, data, options?)
Default Options
const options = {
cache: 'default', // default, no-store, reload, no-cache, force-cache, only-if-cached
credentials: 'same-origin', // same-origin, omit, include
timeout: 30000, // request timeout 30s by default
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
mode: 'cors' // same-origin, no-cors, cors
}
TODO
- d.ts file
- canceling request
- tests coverage