Hari Menon
Hari Menon

Reputation: 35405

Pure HATEOAS vs making too many service calls

I am trying to build a RESTful web service which is supposed to power my UI. If I go by pure HATEOAS principles, I should only be exposing URIs of individual resources in collections. Now, say I have a a parent-child relationship, and each parent can have like 50 children, and the UI requires partial data for all the children also to be shown when the parent is clicked.

If I only expose child URIs with the parent, then the UI will have to make 50 web service calls to get this done. The other approach is to have a separate API which will give out the parent as well as partial info about the children instead of just the URIs. I am sure this is a common enough problem. What is the right balance here? What are some of the gotchas? The "only URI" approach is cleaner from a design perspective, but it could make the UI really slow and put a lot of load on the server because of all these service calls. So, the other approach might be more practical. In your experience, which is better?

Upvotes: 6

Views: 1420

Answers (1)

Darrel Miller
Darrel Miller

Reputation: 142094

You are being misled about what the hypermedia constraint requires. There is nothing that says you cannot include information from your child objects in a representation of the parent object. In fact that's exactly what Hal (a hypermedia type) was designed to enable.

Upvotes: 5

Related Questions