1.1.1 • Published 9 years ago

so-fetch v1.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

so-fetch

A whatwg fetch wrapper meant for redux dispatch

Alt Text

If you aren't Jay - you should use your own discretion when using this.

If you aren't using Redux --- you totally should! Also, dont use this. If you aren't using Thunk Middleware with Redux --- you totally should! Also, dont use this.

Otherwise:

This is meant as a simple wrapper for whatwg fetch with redux/thunk that's meant to make life a little simpler. So-fetch will handle your fetch and dipstach for you, just send it some options and never think about it again! The checkStatus function used under the hood to throw errors is also taken from their example here.

In your /actions folder:

'use strict';

import { soFetch } from 'so-fetch';
import * as constants from './constants';

export function getUser() {
  return soFetch('/users', {
      method: 'get',
      actionType: constants.GET_USER,
      responseBinding: 'user' //defaults to 'payload'
      //when you get a response back from url - will dispatch { type: constants.GET_USER, user: response }
    });
};

###API:

soFetch(url, options)
getQS(params) //This is a helper function used by soFetch to build and encode a query string. Accepts an object of keys - { a: 'a', 'b': { 1: 'one', 2: 'two', 3: 'three'}, c: [ 1, 2, 3] } will return: "?a=a&b[1]=one&b[2]=two&b[3]=three&c[]=1&c[]=2&c[]=3"

####URL This one should be straightforward ####OPTIONS Fetch accepts:

body - an object!

method - a string! 'get'/'post'/'put'/'delete'

actionType - the action you want to dispatch

responseBinding - they key you want to bind payload to

qs - an object! meant to construct your query string

headers - another object - defaults to { 'Accept': 'application/json', 'Content-Type': 'application/json' }

credentials - Much like how you have to include { credentials: 'same-origin' } if you want to send cookies through fetch - we default that behavior always be true (you will always send cookies) if you would like this disabled for certain fetch calls then set to false, or pass in another value and that will get passed in as the value.

Alt Text

1.1.1

9 years ago

1.1.0

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago