iso-request

0.2.0 • Public • Published

TODO: compile to js, and tests, and docs

simple window.fetch wrapper

request = require 'iso-request'

# Automatic json extraction
request '/get'
.then (json) ->
  # parsed json

request '/post', {method: 'POST'}
.then (json) ->
  # parsed json

# Query string object support
request '/getQs', {qs: {a: 2}} # /getQs?a=2
.then (json) ->
  # parsed json

# Errors trigger promise failure
request '/404'
.catch (err) ->
  # RequestError object
  err.res.json().then -> # handle error

# RequestError
class RequestError extends Error
  constructor: ({res}) ->
    @name = 'RequestError'
    @message = res.statusText
    @stack = (new Error()).stack
    @res = res

Readme

Keywords

Package Sidebar

Install

npm i iso-request

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

114 kB

Total Files

9

Last publish

Collaborators

  • zolmeister