1.0.0 • Published 4 years ago

fethttp v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Fetch api wrapper that let you code like angular http service.

The letter F in fethttp stands for fetch api. It just means that its a wrapper around fetch api.

Installation
npm install fethttp --save

or

yarn add fethttp
Setting default config
import {setDefaultConfig} from 'fethttp';
setDefaultConfig({
  credentials : 'included',
  cache : "no-cache",
  headers : {
    "Content-Type": "application/json"
  },
  ...
});

Note that you can't set method or body as default config because thos are going to be taken care of by methods such as fethttp.get, fethttp.post etc.

Usage

GET

import http form 'fethttp';

http.get("https://somerestapiurl").then(response=>console.log(response)).catch(errorResponse=>console.log(errorResponse))

POST

import http form 'fethttp';

let data = {a:1}
http.post("https://somerestapiurl", data).then(response=>console.log(response)).catch(errorResponse=>console.log(errorResponse))

PUT

import http form 'fethttp';

let data = {a:1}
http.put("https://somerestapiurl", data).then(response=>console.log(response)).catch(errorResponse=>console.log(errorResponse))

DELETE

import http form 'fethttp';

http.delete("https://somerestapiurl").then(response=>console.log(response)).catch(errorResponse=>console.log(errorResponse))
Overwriting default config.

You can overwrite the default config that you just set. Every http methods support passing config object as the last parameter. For http.get it's the second parameter. For http.put, http.post, http.delete, the third parameter is config object

http.get("someurl", {credentials:'include', 'Content-Type':'application/json'})

API Docs

http.get(url, configObj)

http.post(url, body, configObj)

http.put(url, body, configObj)

http.delete(url, body, configObj)

1.0.0

4 years ago