{"id":14384949,"url":"https://github.com/lexich/redux-api","last_synced_at":"2025-04-08T12:09:26.860Z","repository":{"id":1100327,"uuid":"40594264","full_name":"lexich/redux-api","owner":"lexich","description":"Flux REST API for redux infrastructure","archived":false,"fork":false,"pushed_at":"2023-01-04T21:41:56.000Z","size":5215,"stargazers_count":494,"open_issues_count":53,"forks_count":88,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-01T11:04:26.491Z","etag":null,"topics":["api","flux","javascript","react","redux","rest"],"latest_commit_sha":null,"homepage":"","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/lexich.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-12T10:11:44.000Z","updated_at":"2025-03-30T08:18:41.000Z","dependencies_parsed_at":"2023-01-13T16:22:13.681Z","dependency_job_id":null,"html_url":"https://github.com/lexich/redux-api","commit_stats":null,"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexich%2Fredux-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexich%2Fredux-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexich%2Fredux-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexich%2Fredux-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lexich","download_url":"https://codeload.github.com/lexich/redux-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838444,"owners_count":21004580,"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":["api","flux","javascript","react","redux","rest"],"created_at":"2024-08-28T18:01:48.440Z","updated_at":"2025-04-08T12:09:26.839Z","avatar_url":"https://github.com/lexich.png","language":"JavaScript","readme":"### Redux-api\nFlux REST API for redux infrastructure\n\n[![Build Status](https://travis-ci.org/lexich/redux-api.svg)](https://travis-ci.org/lexich/redux-api)\n[![NPM version](https://badge.fury.io/js/redux-api.svg)](http://badge.fury.io/js/redux-api)\n[![Coverage Status](https://coveralls.io/repos/lexich/redux-api/badge.png?branch=master)](https://coveralls.io/r/lexich/redux-api?branch=master)\n\n## Introduction\n`redux-api` solves the problem of writing clients to communicate with backends. It generates [actions](http://redux.js.org/docs/basics/Actions.html) and [reducers](http://redux.js.org/docs/basics/Reducers.html) for making AJAX calls to API endpoints. You don't need to write a lot of [boilerplate code](http://redux.js.org/docs/advanced/ExampleRedditAPI.html) if you use `redux` and want to exchange data with server.\n\nInspired by [Redux-rest](https://github.com/Kvoti/redux-rest) and is intended to be used with [Redux](https://github.com/gaearon/redux).\n\n\n## Documentation\nSee [DOCS.md](docs/DOCS.md) for API documentation.\n## Use cases\n* [AuthorizationJWT.md](docs/AuthorizationJWT.md) - example of JWT Authorization  \n* [Scoping.md](docs/Scoping.md) - use scoping or using multiple redux-api instance without naming intersections.\n\n## Install\nWith npm:\n```sh\nnpm install redux-api --save\n```\nWith bower:\n```sh\nbower install redux-api --save\n```\n\nIf you don't use tools like webpack, browserify, etc and you want to load redux-api manually, the best way to add redux-api to your project is:\n```js\n\u003cscript src=\"(...)/redux-api.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  window.ReduxApi = window[\"redux-api\"];\n  // or\n  var ReduxApi = window[\"redux-api\"];\n  // initialization code\n\u003c/script\u003e\n```\n\n=======\n## Remote calls\n\n`redux-api` doesn't bind you to a technology to make AJAX calls. It uses configurable `adapters` - a pretty simple function which receives 2 arguments: `endpoint` and `options`, and returns a Promise as result. The default adapter uses [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), and has an implementation like this:\n```js\nfunction adapterFetch(url, options) {\n  return fetch(url, options);\n}\n```\n\nHowever, you are not tied to using isomorphic-fetch. For instance, if you prefer to use jQuery, you can use the following adapter:\n```js\nfunction adapterJquery(url, options) {\n  return new Promise((success, error)=\u003e {\n    $.ajax({ ...options, url, success, error });\n  });\n}\n```\nThis implementation allows you to make any request and process any response.\n\nAnd of course you have to set up adapter to your `redux-api` instance before using.\n```\n  reduxApi(....).use(\"fetch\", adapterFetch)\n```\n\n=======\n## Examples\n[examples/isomorphic](https://github.com/lexich/redux-api/tree/master/examples/isomorphic) - React + Redux + React-Router + Redux-api with webpack and express + github API\n\n### Example\nrest.js\n```js\nimport \"isomorphic-fetch\";\nimport reduxApi, {transformers} from \"redux-api\";\nimport adapterFetch from \"redux-api/lib/adapters/fetch\";\nexport default reduxApi({\n  // simple endpoint description\n  entry: `/api/v1/entry/:id`,\n  // complex endpoint description\n  regions: {\n    url: `/api/v1/regions`,\n    // reimplement default `transformers.object`\n    transformer: transformers.array,\n    // base endpoint options `fetch(url, options)`\n    options: {\n      headers: {\n        \"Accept\": \"application/json\"\n      }\n    }\n  }\n}).use(\"fetch\", adapterFetch(fetch));\n```\n\nindex.jsx\n```js\nimport React, {PropTypes} from \"react\";\nimport { createStore, applyMiddleware, combineReducers } from \"redux\";\nimport thunk from \"redux-thunk\";\nimport { Provider, connect } from \"react-redux\";\nimport rest from \"./rest\"; //our redux-rest object\n\nconst createStoreWithMiddleware = applyMiddleware(thunk)(createStore);\nconst reducer = combineReducers(rest.reducers);\nconst store = createStoreWithMiddleware(reducer);\n\nfunction select(state) {\n  return { entry: state.entry, regions: state.regions };\n}\n\nclass Application {\n  static propTypes = {\n    entry: PropTypes.shape({\n      loading: PropTypes.bool.isRequired,\n      data: PropTypes.shape({\n        text: PropTypes.string\n      }).isRequired\n    }).isRequired,\n    regions: PropTypes.shape({\n      loading: PropTypes.bool.isRequired,\n      data: PropTypes.array.isRequired\n    }).isRequired,\n    dispatch: PropTypes.func.isRequired\n  };\n  componentDidMount() {\n    const {dispatch} = this.props;\n    // fetch `/api/v1/regions\n    dispatch(rest.actions.regions.sync());\n    //specify id for GET: /api/v1/entry/1\n    dispatch(rest.actions.entry({id: 1}));\n  }\n  render() {\n    const {entry, regions} = this.props;\n    const Regions = regions.data.map((item)=\u003e \u003cp\u003e{ item.name }\u003c/p\u003e)\n    return (\n      \u003cdiv\u003e\n        Loading regions: { regions.loading }\n        \u003cRegions/\u003e\n        Loading entry: {entry.loading}\n        \u003cdiv\u003e{{ entry.data.text }}\u003c/div\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nconst SmartComponent = connect(select)(Application);\n\nReact.render(\n  \u003cProvider store={store}\u003e\n    \u003cSmartComponent /\u003e\n  \u003c/Provider\u003e,\n  document.getElementById(\"content\")\n);\n```\n\n### [Releases Changelog](https://github.com/lexich/redux-api/releases)\n","funding_links":[],"categories":["JavaScript","Marks"],"sub_categories":["[React - A JavaScript library for building user interfaces](http://facebook.github.io/react)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexich%2Fredux-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexich%2Fredux-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexich%2Fredux-api/lists"}