npm.io
0.7.9 • Published 6 years ago

kayden

Licence
ISC
Version
0.7.9
Deps
1
Size
111 kB
Vulns
0
Weekly
0

Kayden - (Beta)

Overview

A light weight promise based request client.

Both XMLHttpRequests for browsers and HTTP for node.js

Installation

$ npm install kayden

Usage

Get
import kayden from 'kayden'

const url = 'https://jsonplaceholder.typicode.com/posts'

const data = async () => {
  try {
    const response = await kayden.get(url)
    return response
  } catch (e) {
    console.warn(e)
  }
}
Post
import kayden from 'kayden'
const config = {
  url: 'https://jsonplaceholder.typicode.com/posts',
  body: {
    id: 101,
    title: 'foo',
    body: 'bar',
    userId: 1
  },
}

const data = async () => {
  try {
    const response = await kayden.post(config.url, config.body)
    return response
  } catch (e) {
    console.warn(e)
  }
}
.then().catch() syntax
import kayden from 'kayden'

  kayden.get('https://jsonplaceholder.typicode.com/posts')
  .then(res => {
    console.log(res)
  })
  .catch(e => {
    console.warn(e)
  })
}

Methods

Methods used on the instances:

kayden#get(url [, options])
kayden#post(url [, body] [, options])
kayden#put(url [, body] [, options])
kayden#patch(url [, body] [, options])
kayden#delete(url [, options])

Keywords