This is simply an architecture question, which I couldn't find the answer to anywhere.
The current scenario is - There is a server that accepts GET requests on one end point. Each request body will have the same structure : requestType (string) and payload (json). The requestType is mapped with a switch case in the backend to essentially just mimic multiple end points.
Now, while creating an Angular/NgRx application that relies on this backend, how should I manage the services? There are about 40 requestTypes, should I make 40 services? Should I create one service that uses httpClient to hit that singular end point and then use a lot of effects to listen to actions and then create the right payload and use the service?
Which approach would be easier to test?
Depends on what the backend returns.
If it returns the same kind of data with different flags you can use one store feature with one action and one effect, the action should have type
property.
If it returns different kind of data, for example Users / Companies etc then, unfortunately, you have to create 40 store features, write actions and effects for them. To reduce the boilerplate process you can try to use ngrx/data
, I can't call it a very good lib, but in this case it will allow you to specify 40 types and the rest will be done automatically.
Otherwise try to create factory functions and classes.