{"id":17205176,"url":"https://github.com/sonmezonur/redux-rest-middleware","last_synced_at":"2025-03-25T10:16:43.725Z","repository":{"id":57161550,"uuid":"138425374","full_name":"sonmezonur/redux-rest-middleware","owner":"sonmezonur","description":"Fully customizable REDUX middleware for async actions","archived":false,"fork":false,"pushed_at":"2019-02-16T21:23:18.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T06:14:56.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonmezonur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-23T18:38:16.000Z","updated_at":"2019-02-16T21:24:58.000Z","dependencies_parsed_at":"2022-09-08T09:10:52.704Z","dependency_job_id":null,"html_url":"https://github.com/sonmezonur/redux-rest-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonmezonur%2Fredux-rest-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonmezonur%2Fredux-rest-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonmezonur%2Fredux-rest-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonmezonur%2Fredux-rest-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonmezonur","download_url":"https://codeload.github.com/sonmezonur/redux-rest-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245440577,"owners_count":20615633,"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":[],"created_at":"2024-10-15T02:24:31.709Z","updated_at":"2025-03-25T10:16:43.696Z","avatar_url":"https://github.com/sonmezonur.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"redux-rest-middleware\n---\nFully customizable REST middleware with zero dependency for your redux apps.\n\nUsage\n===\n\n- Setting up basic configuration before attaching middleware to redux store\n\n```javascript\nimport { applyMiddleware, createStore } from 'redux'\nimport restMiddleware from '@sonmezonur/redux-rest-middleware'\n\nconst apiSettings = {\n  baseURL: process.env.REQUEST_URL,\n  headers: {\n    'Accept': 'application/json, application/xml, text/plain, text/html, *.*',\n    'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'\n  },\n  params: {\n    apiKey: process.env.API_KEY\n  }\n}\n\nconst store = createStore(\n  reducers, \n  initialState,\n  applyMiddleware(restMiddleware(apiSettings))\n)\n```\n\n- Action\n\n```javascript\nconst getAction = (id) =\u003e {\n  return {\n    fetch: {\n      method: 'GET', // or 'POST', 'PUT', 'DELETE', 'PATCH'\n      endpoint: `/actions/${id}`,\n      types: {\n        request: 'FETCH_ACTION', // must\n        success: 'FETCH_ACTION_SUCCESS', // optional\n        failure: 'FETCH_ACTION_FAILURE' // optional\n      },\n      onSuccess: (response) =\u003e {\n        // handle response on success\n      },\n      onError: (err) =\u003e {\n        // handle error\n      }\n    }\n  }\n}\n```\n\n- Reducer\n\n```javascript\nconst actionHandler = (state, { type, payload }) =\u003e {  \n  switch (type) {\n    case 'FETCH_ACTION':\n      return {\n        ...state,\n        isFetching: true\n      }\n    case 'FETCH_ACTION_SUCCESS':\n      return {\n        ...state,\n        isFetching: false,\n        payload: payload\n      }\n    case 'FETCH_ACTION_FAILURE':\n      return {\n        ...state,\n        error: payload\n      }\n  }\n}\n```\n\n- Fetch Parameters\n  - `method`: Request Type - 'GET', 'DELETE', 'POST', 'PATCH', 'PUT'\n  - `endpoint`: Request source\n  - `params`: Query params for the request(on JSON format)\n  - `types`: Action types - 'request'(must), 'success', 'failure'\n  - `onSuccess`: Function to handle successful requests\n  - `onFailure`: Function to handle error responses\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonmezonur%2Fredux-rest-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonmezonur%2Fredux-rest-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonmezonur%2Fredux-rest-middleware/lists"}