we have api uses spring jpa , provides access data in our database via rest. api exposed in hateoas fashion (we using spring implementation).
we considering whether stick approach or code s=our own rest interface manually. now, have read lot of articles hateoas not sure what's big advantage of using it. sure, understand can navigate through using links still have know existence of links @ each level, right?
to illustrate problem, let's have following structure:
server.com/ - /store - /users/ server.com/users - /managers/ - /other/ server.com/managers - list of entities ids
i want consume api , 'manager' entities (located under server.com/users/managers
)
what correct way when using spring boot links?
option one:
requestentity<void> request = requestentity.get("server.com/users/managers").accept(hal_json).build(); final resource<manager> managers = resttemplate.exchange(request, new resourcestype<manager>() { }).getbody();
option two:
// global endpoint requestentity<void> request = requestentity.get("server.com").accept(hal_json).build(); final resource<object> rootlinks = resttemplate.exchange(request, new resourcetype<object>() { }).getbody(); links links = new links(rootlinks.getlinks()); final link userlink = links.getlink("users").expand(); // users endpoint request = requestentity.get(uri.create(userlink.gethref())).accept(hal_json).build(); final resource<object> managerlinks = resttemplate.exchange(request, new resourcetype<object>() { }).getbody(); links = new links(managerlinks.getlinks()); final link managerlink = links.getlink("managers").expand(); // managers endpoint request = requestentity.get(uri.create(managerlink.gethref())).accept(hal_json).build(); final resources<manager> resourceaccounts = resttemplate.exchange(request, new resourcestype<manager>() { }).getbody();
the first option 1 seems straightforward , can entities single request. however, fail see hot hateoas beneficial if use approach. spring documentation states, using hardcoded links not recommended.
the second approach seems more in hateoas fashion creates 3 requests resource location know. doesn't seem right either.
i know it's dummy question can explain me great idea behind hateoas missing?
with hateoas server can guide client through provided links. contract between server , client link's relation type , media type. server can, providing or not providing links on same resource representation, give client information if resource in state editing enabled or not enabled or if user authorized operation on resource , on. server can change urls without breaking contract.
Comments
Post a Comment