Call some different restful services from front-end

88 views Asked by At

Imagine I have an angular project as a front-end which communicates with some other projects which are restful services.

In some pages I need to fetch some data from different restful services, Is that okay to request any restful service individually in angular? Or call one restful service which itself call other restful services in back-end?

Or I have to call one restful service but add other entities to this DbContext which I need here just to query?

1

There are 1 answers

0
Savvas Kleanthous On

It depends on what you're doing, but I would say mostly it's OK to do this. This is an established microservices pattern called "Composite UI". See this for details: https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/architect-microservice-container-applications/microservice-based-composite-ui-shape-layout

If your microservices are using the CQRS pattern, (while still not wrong) you may be missing an opportunity to compose a view-specific "view model". However, if you're composing\showing data from multiple domains I would say that it's still better to just call multiple microservices to retrieve the data you need.

The only problem you may be introducing if you're not careful, is introducing projection logic (which is not THAT bad) or business logic (very very bad) in your client code if you're doing any processing on the data you receive in order to display it. Composite UI is meant to server a UI with clearly separated sections.