idiot

Simple JSON REST client

Usage no npm install needed!

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

README

idiot

A simple JSON REST client

  • Lightweight for the browser and Node.js
  • Supports Promises and callbacks

Build Status

Install

npm install --save idiot

Usage

const client = require('idiot')({
  baseUrl: 'http://localhost:8080/api'
});

return client.get('/movies').then(data => {
  // got a 2xx response from http://localhost:8080/api/movies
});

Documentation

new Idiot( options )

  • options {Object}
    • baseUrl {String} (required) each request url is formed by appending the uri to this value
    • Promise {Function} (optional) specify your own Promise library

client.delete( uri, [query], [cb] )

  • uri {String}
  • query {Object} (optional) querystring values
  • cb {Function} (optional) callback

client.get( uri, [query], [cb] )

  • uri {String}
  • query {Object} (optional) querystring values
  • cb {Function} (optional) callback

client.patch( uri, body, [query], [cb] )

  • uri {String}
  • body {Object}
  • query {Object} (optional) querystring values
  • cb {Function} (optional) callback

client.post( uri, body, [query], [cb] )

  • uri {String}
  • body {Object}
  • query {Object} (optional) querystring values
  • cb {Function} (optional) callback

client.put( uri, body, [query], [cb] )

  • uri {String}
  • body {Object}
  • query {Object} (optional) querystring values
  • cb {Function} (optional) callback

client.request( options, [cb] )

  • options
    • method
    • uri
    • body
    • query
    • aborter
  • cb (optional)