0.0.7 • Published 7 years ago

redux-fetch-helpers v0.0.7

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

This is a tiny library for generating actions which fetch things.

E.g

actionCreator = fetchActionCreator({
    url: "http://testserver/someurl/",
    fetchOptions: {
        method: "POST",
        body: JSON.stringify({some: "data"})
    },
    actionType: "SOME_ACTION_TYPE",
    responseConfig: {
        201: {created: true},
        401: new Error("Unauthorized"),
        other: new Error("Other!"),
    }
})

Would create an action creator which will send POST requests to "http://testserver/someurl" using redux-thunk. The fetchOptions and url are passed to fetch. When the request begins an action like

{
    type: "SOME_ACTION_TYPE",
    meta: {sequence: "BEGIN"},
}

Will be dispatched. When the request completes sucesfully:

{
    type: "SOME_ACTION_TYPE",
    meta: {sequence: "COMPLETE"},
}

The responseConfig map is used to map statuses to action payloads. If a value is a function then that function will be called with the body of the response (parsed into JS if content type is "application/json".

0.0.7

7 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2-alpha.6

9 years ago

0.0.2-alpha.5

9 years ago

0.0.2-alpha.4

9 years ago

0.0.2-alpha.3

9 years ago

0.0.2-alpha.2

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago