Reputation: 3131
What is HATEOAS way of discovering existing resources? Let's say I have a collection of resources and normally client first gets the list of resources and then it can navigate to each resource from the list, because server provides information how to get each resource. But what if client needs to get particular resource directly without fetching list first?
An example could be a web application that has a page with list of items (for example users) /api/users
and user can navigate to user page where client fetch single user /api/users/1234
. Frontend app has its own routing and user page can have following URL https://example.com/users/1234/details
). Now imagine that client opens user page directly, how it can know which endpoint to use to get user data from the server?
Upvotes: 0
Views: 120
Reputation: 97783
I think you are conflating two different levels of interaction:
The front-end application might provide a page per user, a summary page for a group of users, or embed the user information in a widget on every page's header.
The API, on the other hand, might provide an end-point to list groups, one to list users in a group, one to get details of a particular user, etc. HATEOAS is talking about how an API client would discover these.
So in your scenario, it might look like this:
https://example.com/users/1234/details
https://example.com
will have an internal function to fetch the user details for ID 1234
GET /users/
or GET /users/?filter=id:1234
- retrieve a list of zero or more user records1234
and extract a link to the related user details resourceGET
the resource indicated by that linkUpvotes: 1