HATEOAS and rest client
See original GitHub issueMicroprofile rest client is still rather new and it is hard to find example for some specific usage, and that is way I’m asking here.
Problem that I now facing is how to use rest client when rest endpoint implements HATEOAS. In this example bellow we have some endpoint https://localhost1/rest/management
that produces output :
{
"departmentId": 10,
"departmentName": "Administration",
"locationId": 1700,
"managerId": 200,
"links": [
{
"href": "https://localhost2/rest/employees",
"rel": "employees",
"type" : "GET"
}
]
}
My question is about how to implement rest client interface that gets content from resource(s) that is defined in links
.
Do we need to build new client interface(we cannot override base url for client interface already created?) for each link in links? Is building new client interface expensive operation, because we can have a lot of links?
It would be nice that solution for given problem can be implemented with microprofile rest client CDI support.
Any guidance to existing documentation, example or pointer in direction to solve problem are welcome.
Thanks on your very good work on Microprofile project.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
@konjp The discussion about the pros and cons of HATEOAS are tiresome. It probably can be solved as easy as the discussion about tabs and spaces.
But you have a very specific problem at hand that could be solved even with the static nature of the MP Rest Client (if it’s not too late): You can simply add a
List<Link> links
field to yourManagement
DTO. TheLink
class would have fields forhref
,rel
, andtype
. Then you can handle the navigation ‘by hand’.If that’s a satisfying response for you, we could close this issue.
Like in most case when we have problems, they almost always come as chain of events 😃. In this particular case we do not have control of rest endpoint and we need information from
links
section, therefore it is not option to ignore links.In team we already discussed situation that @andymc12 mentioned. Endpoint is not much dynamic, therefor static (fixed) approach from client side is a option. I know somebody can say then you do not facilities one one major advantage HATEOAS like structure, namely that server can evolve independently from client. Solution that we think to implement to follow links and get content is given bellow like pseudo-code:
@derekm can you little elaborate more on how URL rewrite is done on client side.
Just to add little bit to discussion about linking, a lot of implementations f.e. HAL, Siren or Atom have linking implemented in content body.