
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
Disfetch is a library for sending HTTP requests and dispatching Redux actions accordingly.
A common task in most Redux-based applications is sending requests to a server and dispatching actions based on the response. This library should simplify that and help you write less verbose code.
You can use this in the same way as you would use the axios library.
// config always has the lowest priority when considering URL, method and data properties
disfetch('/') // the first parameter is always the URL, regardless of the method
disfetch('/', { method: 'get' }) // the default method
disfetch.request('/') // an alias to calling the disfetch instance directly
disfetch.request('/', { method: 'get' })
disfetch.get('/')
disfetch.get('/', { headers: { /* ... */ } }) // you can also use delete, head and options methods
disfetch.post('/')
disfetch.post('/', { id: 1 })
disfetch.post('/', { id: 1 }, { headers: { /* ... */ } }) // you can also use put and patch methods
The interesting stuff comes with using the with method.
disfetch.with(dispatch, 'APPROVE').get('/')
This will send a request to the specified URL ('/') and dispatch these actions:
// before sending the request
{
type: 'APPROVE_REQUEST',
payload: config, // parsed request fetch config (may not include axios default values)
meta: {
request: config // also the parsed request config (for convenience)
}
}
// if the response is successful
{
type: 'APPROVE_SUCCESS',
payload: response.data,
meta: {
request, // request config (from response.request, made available by axios)
response,
}
}
// if the response is not successful
{
type: 'APPROVE_FAILURE',
payload: response.data || response.statusText || response.status || error.message,
meta: {
request, // request config (from response.request, made available by axios)
response // may not be available
}
}
You can also pass a configuration object instead of a string.
disfetch.with(dispatch, {
requestAction: 'APPROVE_REQUEST', // mixed types are allowed
successAction: {
type: 'APPROVE_SUCCESS'
},
failureAction: (payload, { request, response }) => ({
type: 'APPROVE_FAILURE',
payload: payload,
meta: {
request,
response
}
})
}).post('/', { value: 'waffle' }).then((response) => console.log(response))
This will send a POST request to the speciifed URL with the supplied JSON body.
An action of 'APPROVE_REQUEST' type will be dispatched before sending the request.
If it results in a successful response, the successAction is filled with response data and dispatched.
If it results in a failed response (or the request could not be sent at all), the failureAction function is called and the return value is dispatched.
// these methods return a promise resolved with the response object (see response schema)
disfetch( url [, fetchConfig ] )
disfetch.request( url [, fetchConfig ] )
disfetch.delete( url [, fetchConfig ] )
disfetch.get( url [, fetchConfig ] )
disfetch.head( url [, fetchConfig ] )
disfetch.options( url [, fetchConfig ] )
disfetch.patch( url [, data [, fetchConfig ] ] )
disfetch.post( url [, data [, fetchConfig ] ] )
disfetch.put( url [, data [, fetchConfig ] ] )
// these methods return a new disfetch instance with new configs set (merged recursively)
disfetch.create( [ dispatchConfig [, fetchConfig ] ] )
disfetch.with( [ dispatch, ] dispatchConfig )
// these methods return the original disfetch instance, its configs are RESET beforehand
// using these methods will mutate the instance, therefore their use is discouraged
disfetch.setDispatchConfig( [ dispatchConfig ] )
disfetch.setFetchConfig( [ fetchConfig ] )
It is the unmodified axios response schema.
It is merged with the default dispatch configuration of the instance (supplied one takes precedence). The object can be passed as an argument to the with or create method. Listed below are possible properties of the config. Defaults can also be found here.
dispatchThe dispatch function to dispatch the actions with. Can be passed as the first argument to the with method.
requestAction, successAction, failureActionActions to be dispatched before sending a request or after receiving a response (a successful one or a failed one).
universalAction.type property is the value. Then it behaves as if it were an object.payload and meta properties are set depending on the event:
payload: requestmeta: { request }payload: response.datameta: { request, response }payload: response.data || response.statusText || response.status || error.messagemeta: { request, response }payload and meta arguments (depending on the event). The return value is then dispatched.transformResponse and transformRequest properties in the fetch config.universalActionDefault action for all events (request, success and failure). Event actions override the dispatch of this action (event actions take precedence, but if e.g. only one event action is specified, universal action is still dispatched for other events).
requestAction).dispatchObjectOnRequest).requestSuffix, successSuffix, failureSuffixSuffixes to use for action types of corresponding events, default values are '_REQUEST', '_SUCCESS' and '_FAILURE'.
smartSuffixingIf universalAction is a string and ends with any of the suffixes, they are removed and replaced with the correct one. The default value is true (this behaviour is enabled).
dispatchObjectOnRequest, dispatchFunctionCallOnRequestIf universalAction is an object, it will also be dispatched on request event. If it's a function, it is called and the return value will also be dispatched on request event. The default value is false. If you pass an object or a function to universalAction, the default behaviour is to dispatch it only after the request is fully handled (as finally would).
argsArray of arguments to call the functions with (appended to the end, an alternative to fn.bind). The default value is an empty array. You can also provide a single non-array value. Note that the first two default arguments (payload, meta) ARE preserved.
It is merged with the default config of the instance (supplied one takes precedence). Passing it to any of the request methods will NOT mutate the instance or create a new one – the config will be used just for the request. Listed below are possible properties of the config.
jwtWill add an 'Authorization: Bearer ' + jwt header if an encoded JSON Web Token string is supplied.
The rest is passed straight to axios. See the axios request config.
FAQs
Library for sending HTTP requests and dispatching Redux actions accordingly.
We found that disfetch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.