rest-trankil.js

Make fetch + async call easy with rest-trankil.js

Usage no npm install needed!

<script type="module">
  import restTrankilJs from 'https://cdn.skypack.dev/rest-trankil.js';
</script>

README

rest-trankil.js

Usage

Init

import Rest from 'xeonys-rest-client'
import { store } from './store'

const headers = () => ({
  Authorization: `token ${store.getState().user.token}`,
  'Content-Type': 'application/json',
})

export new Rest(headers)

Need a fetch polyfill for IE, and babel-polyfill for every browsers.

GET

const res = await rest.get(url, useCustomHeader = true)

POST

const res = await rest.post(url, body, useCustomHeader = true)

PUT

const res = await rest.put(url, body, useCustomHeader = true)

PATCH

const res = await rest.patch(url, body, useCustomHeader = true)

Run and code

yarn && yarn start