Inspiration
Working with REST-api and redux, using common practice, we always create almost same actions and reducers to send HTTP request to different endpoints. This will lead to problem that our projects will always have lot of duplicated code. For example:
This example does not contains error handling, loading, caching data, authorization, options, filters ... And basically we always copy paste this code from file to file and rename function names and constants values
Standard flow
In general, working with HTTP requests we may need to have next flow:
- Set loading flag and clear previous errors if exist
- Sent HTTP request
- Toggle loading flag, save response (error or data).
- Save some meta data for example query string
REST GRUD
This module was build using REST API principles.
Common REST GRUD:
So in total we have 1 Model User
and 7 possible options to work with this model.
Based on REST principles we can make universal url /api/v1/users/:id?
to describe all possible flows.
This url syntax will be compiled using path-to-regex that helps us to have 1 universal url for all possible actions.
So that now we have universal url and we can now use HTTP methods to describe what action do we need.