0.1.15 • Published 6 years ago

kefir-fetch v0.1.15

Weekly downloads
49
License
-
Repository
github
Last release
6 years ago

kefir-fetch

Kefir wrapper around fetch with JSON-friendly defaults

Installation

npm install kefir-fetch

Usage

fetch$(method, path, options?)

The optional options argument may include:

  • body: JSON request body
  • query: JSON query object, which is encoded and appended to the URL
  • headers: Override HTTP headers, which by default are:
    • "Accept": "application/json"
    • "Content-Type": "application/json"
  • base_url: Base URL to prepend path to, useful for non-web apps

Default options

fetch$.setDefaultOptions(options)

To override the default options for all requests, use setDefaultOptions.

Examples

fetch$ = require 'kefir-fetch'

# Get an item

fetch$('get', '/item/55.json').onValue (item) ->
    console.log "Got item:", item

# Update some item, using the body option

update = {score: 0.43}

fetch$('put', '/items/55.json', {body: update}).onValue (updated) ->
    console.log "Updated item:", updated

# Search for some items, using the query option

search = {q: "some"}

fetch$('get', '/items.json', {query: search}).onValue (items) ->
    console.log "Found items:", items
0.1.15

6 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago