question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HATEOAS and rest client

See original GitHub issue

Microprofile 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:open
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
t1commented, Jan 23, 2020

@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 your Management DTO. The Link class would have fields for href, rel, and type. Then you can handle the navigation ‘by hand’.

If that’s a satisfying response for you, we could close this issue.

0reactions
konjpcommented, Mar 20, 2018

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:

foreach link in links and type='GET' do 
RemoteApi remoteApi = RestClientBuilder.newBuilder().baseUrl(link.url).build(RemoteApi.class);

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HATEOAS Driven REST APIs
HATEOAS (Hypermedia as the Engine of Application State) is a constraint of the REST application architecture which uses hypertext in API ...
Read more >
Building a Hypermedia-Driven RESTful Web Service - Spring
You will build a hypermedia-driven REST service with Spring HATEOAS: a library of APIs that you can use to create links that point...
Read more >
HATEOAS and Why It's Needed in RESTful API?
HATEOAS stands for Hypermedia as the Engine of Application State and it is a component of RESTful API architecture and design.
Read more >
REST API — What Is HATEOAS? - DZone
In this article, we looked at what HATEOAS stands for. With HATEOAS, responses to REST requests return not just the data, but also...
Read more >
HATEOAS - Wikipedia
With HATEOAS, a client interacts with a network application whose application servers provide information dynamically through hypermedia. A REST client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found