Have you ever thought of the simplest way to create a REST API client in your React application, and spend less time sitting and writing boring seamless actions and reducers, updating them for new definitions and so on?
I spend a lot of time creating front-end applications that communicate with services through REST API, and I required a simple and easy-to-understand solution that would allow me to write less code and create powerful API clients with
Also, my point was to make it maintainable by other developers too. So everyone can understand the syntax and understand the API structure that is defined in the classes.
My choice came to the OpenAPI standard. This is simple and fulfils all my requirements, making it easy to understand, modify, and maintain through time.
Decided: OpenAPI 2.0, because of the limitations of the plugins that are used, I had to choose not the latest version.
You can view this project on GitHub: react-redux-generator, it is inactive development at this time.
In the development version, that is currently up on GitHub, you are able to generate
utils files automatically from the Swagger file.
The next step is to make a generator file for action
reducer, that can be automatically populated with reducer switch actions and set data it is receiving from the API.
This part requires a deeper understanding of general practices in the development of reducers with react & immer.js.
Please check this project on GitHub, try it yourself, and contribute.
If you find any bug please don’t hesitate to create an issue. Currently, the project is in development so some features can be unsteady or be in development, keep this in mind.