Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding HTTP method to Spring HATEOAS links

I am wondering if it is possible to add HTTP method to the links created with Spring HATEOAS. I would like the link to look something like:

{
    "href":http://localhost:8080/admin/users",
    "rel": "add",
    "method": "POST"
}

{
    "href":http://localhost:8080/admin/users/john",
    "rel": "remove",
    "method": "DELETE"
}

I couldn't find anything which would allow me to add "method" to the link.

like image 778
MrkK Avatar asked Aug 26 '14 19:08

MrkK


People also ask

What is HATEOAS links?

HATEOAS stands for Hypermedia as the Engine of Application State and it is a component of RESTful API architecture and design. With the use of HATEOAS, the client-side needs minimal knowledge about how to interact with a server.

What is org Springframework HATEOAS?

Spring HATEOAS provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and especially Spring MVC. The core problem it tries to address is link creation and representation assembly.


2 Answers

That wouldn't make sense. The href specifies the address of some resource, and the rel tells how it's related to the current resource. The HTTP method indicates what the client wants to do to it, which isn't a part of the relationship between the two.

In your example, the "remove" relation doesn't make sense: HTTP specifies the DELETE verb, and the semantics of

DELETE http://localhost:8080/admin/users/john

are already known. Similarly, POST creates a new resource, so specifying /admin/users is sufficient for a client to list the users (with GET) or add a new user (with POST).

like image 113
chrylis -cautiouslyoptimistic- Avatar answered Oct 04 '22 02:10

chrylis -cautiouslyoptimistic-


You should use the relation "edit".

In the section (11.1) from the Atom Pub RFC (https://www.rfc-editor.org/rfc/rfc5023) which defines that you can send PUT/DELETE/GET requests to this URI of the edit relation.

like image 31
Waldemar Schneider Avatar answered Oct 04 '22 04:10

Waldemar Schneider