{"id":15098865,"url":"https://github.com/charlesstover/fetch-action-creator","last_synced_at":"2025-10-08T03:31:51.432Z","repository":{"id":57185438,"uuid":"115556659","full_name":"CharlesStover/fetch-action-creator","owner":"CharlesStover","description":"Fetches using standardized, four-part asynchronous actions for redux-thunk.","archived":true,"fork":false,"pushed_at":"2020-07-17T21:41:55.000Z","size":60,"stargazers_count":28,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-16T01:12:52.728Z","etag":null,"topics":["async","asynchronous","chai","es6","javascript","js","mocha","npm","npm-module","npm-package","npmjs","react-redux","redux","redux-actions","redux-thunk","thunk","travis","travis-ci","travisci","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fetch-action-creator","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CharlesStover.png","metadata":{"files":{"readme":"README-v1.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-27T20:51:53.000Z","updated_at":"2024-02-26T08:23:30.000Z","dependencies_parsed_at":"2022-09-06T04:02:17.330Z","dependency_job_id":null,"html_url":"https://github.com/CharlesStover/fetch-action-creator","commit_stats":null,"previous_names":["charlesstover/async-action","charlesstover/thunk-action-creator","quisido/fetch-action-creator","charlesstover/fetch-action-creator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlesStover%2Ffetch-action-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlesStover%2Ffetch-action-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlesStover%2Ffetch-action-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlesStover%2Ffetch-action-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CharlesStover","download_url":"https://codeload.github.com/CharlesStover/fetch-action-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235678929,"owners_count":19028301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","asynchronous","chai","es6","javascript","js","mocha","npm","npm-module","npm-package","npmjs","react-redux","redux","redux-actions","redux-thunk","thunk","travis","travis-ci","travisci","typescript"],"created_at":"2024-09-25T17:01:09.201Z","updated_at":"2025-10-08T03:31:46.132Z","avatar_url":"https://github.com/CharlesStover.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-action-creator\nFetches using standardized, four-part asynchronous actions for redux-thunk.\n\nDispatch a single, asynchronous action that fetches a request, and your redux store will receive corresponding actions when the request (1) dispatches, (2) receives a response, (3) encounters an error, and/or (4) is aborted.\n\n[![package](https://img.shields.io/github/package-json/v/CharlesStover/fetch-action-creator.svg)](https://github.com/CharlesStover/fetch-action-creator/)\n[![build](https://travis-ci.com/CharlesStover/fetch-action-creator.svg)](https://travis-ci.com/CharlesStover/fetch-action-creator/)\n[![downloads](https://img.shields.io/npm/dt/fetch-action-creator.svg)](https://www.npmjs.com/package/fetch-action-creator)\n[![minified size](https://img.shields.io/bundlephobia/min/fetch-action-creator.svg)](https://www.npmjs.com/package/fetch-action-creator)\n[![minzipped size](https://img.shields.io/bundlephobia/minzip/fetch-action-creator.svg)](https://www.npmjs.com/package/fetch-action-creator)\n\n## Install\n* `npm install fetch-action-creator --save` or\n* `yarn add fetch-action-creator`\n\nYour redux store must be using the `thunk` middleware.\n\n## Use\n```JS\nimport fetchActionCreator from 'fetch-action-creator';\nconst myFetchAction = () =\u003e\n  fetchActionCreator(\n    url,\n    requestInit,\n    createRequestAction,\n    createReceiveAction,\n    createErrorAction,\n    createAbortAction,\n    conditional\n  );\n\ndispatch(myFetchAction()) // fetches url, dispatching asynchronous actions\n```\n\n## Example\n```JS\nimport fetchActionCreator from 'fetch-action-creator';\nconst fetchEmployees = () =\u003e\n  fetchActionCreator(\n\n    // URL to request.\n    'https://my.business.com/employees.json',\n\n    // Fetch options.\n    {\n      body: 'please',\n      headers: {\n        'Content-Type': 'text/plain; charset=utf-8'\n      },\n      method: 'GET'\n    },\n\n    // Action for when the request has dispatched.\n    (abortController) =\u003e ({\n      type: 'REQUEST_EMPLOYEES',\n      abortController\n    }),\n\n    // Action for when the server has responded.\n    (employees) =\u003e ({\n      type: 'RECEIVE_EMPLOYEES',\n      employees\n    }),\n\n    // Action for when an error has occurred.\n    (err, statusCode) =\u003e ({\n      type: 'EMPLOYEES_ERROR',\n      error: err,\n      statusCode\n    }),\n\n    // Action for when the request has been aborted.\n    () =\u003e ({\n      type: 'ABORT_EMPLOYEES'\n    }),\n\n    // Conditional function for when to disregard this action entirely.\n    (state) =\u003e {\n\n      // Don't fetch twice.\n      if (\n        state.employees.isFetching ||\n        Array.isArray(state.employees.list)\n      ) {\n        return false;\n      }\n\n      return true;\n    }\n  );\n```\n\n## Parameters\n\n* ### url: string\n  The URL to which you are dispatching a fetch request.\n\n* ### requestInit: any\n  The fetch options which you are including in your fetch request _or_ a function that returns said options.\n\n* ### createRequestAction: (abortController: AbortController | null) =\u003e AnyAction\n  An action creator that is called when your fetch request has been dispatched.\n  #### Parameters\n  * ##### abortController: AbortController | null\n    An AbortController instance that controls that abort signal for the fetch request.\n\n    If you desire to abort any of your fetch requests, you should store this instance in your redux state.\n\n    If the user's browser does not support aborting requests, the value will be `null`.\n\n* ### createReceiveAction: (content: Object | string, statusCode: number, headers: Headers) =\u003e AnyAction\n  An action creator that is called when your fetch request has received a response.\n  #### Parameters\n  * ##### content: Object | string\n    A JavaScript object or string with which the server responded to the request.\n  * ##### statusCode: number\n    The status code with which the server responded to the request.\n  * ##### headers: Headers\n    An instance of `Headers` that contains the headers with which the server responded to the request.\n\n* ### createErrorAction: (error: string, statusCode: null | number) =\u003e AnyAction\n  An action creator that is called when an error occurs.\n  #### Parameters\n  * ##### error: string\n    A string containing the error message. This may be either a JavaScript error or the response from the server.\n  * ##### statusCode: null | number\n    The status code with which the server responded to the request. If no status code exists (such as during a JavaScript error), the value is `null`.\n\n* ### createAbortAction: () =\u003e AnyAction\n  An action creator that is called when the fetch request is aborted.\n\n  _See also:_ createRequestAction / Parameters / abortController\n\n* ### conditional: (state: any) =\u003e boolean\n  If present, this function is called prior to the fetch request.\n\n  If it returns true, the fetch request will continue. If it returns false, the entire asynchronous action will be ignored.\n  #### Parameters\n  * ##### state: any\n    Your current redux state.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlesstover%2Ffetch-action-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlesstover%2Ffetch-action-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlesstover%2Ffetch-action-creator/lists"}