Skip to content

Zorium/iso-request

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 100.0%