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.
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.
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.
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
).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With