1.0.1 • Published 3 years ago

fetchay v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

fetchay

Lite HTTP request module wrapper for fetch API

Installation

npm i fetchay

Methods

GET:

get(url, args)

POST:

post(url, args)

PATCH:

patch(url, args)

PUT:

put(url, args)

DELETE:

delete_(url, args)

Argument formats

url

  • string or object
{
  url: <string>,
  query: <object>,
  hash: <string>,
}

args

  • undefined or object
{
  body: <object>,
  headers: <object>,
}

Response

{
  status: <number>,
  data: <object>|<string>, // string if not valid json
  ok: <boolean>, // false if 400+ status, also throws error
  statusText: <string>,
  url: <string>,
  headers: <Response.headers>
}

Usage

import {get, post} from 'fetchay'

accesing direct url

get("api/test").then(resp => {
    console.log(resp);
}).catch(er => {
    console.log(er);
})

url with dynamic query

get({ 
    url: "/api/test",
    query: { status: 'active' } 
}).then(resp => {
    console.log(resp)
}).catch(er => {
    console.log(er)
})

adding payload and changing header

post("/api/test", { 
    body: { test: 123 },
    headers: { 'Authorization': 'Token' } 
}).then(resp => {
    console.log(resp)
}).catch(er => {
    console.log(er);
})
1.0.1

3 years ago

1.0.0

3 years ago