kayden

Request client

Usage no npm install needed!

<script type="module">
  import kayden from 'https://cdn.skypack.dev/kayden';
</script>

README

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])