Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HATEOAS links with PUT/POST

What would be the best way to represent a HATEOAS link for a POST/PUT/PATCH on a resource? These operations have payload but we won't have an option to represent the payload in HATEOAS link as they aren't predetermined and can be heavy. So would it suffice just specifying the end point and specifying the operation?

Any samples or examples would be greatly appreciated for a JSON response with HATEOAS POST/PUT/PATCH link.

like image 801
g0c00l.g33k Avatar asked Sep 09 '15 02:09

g0c00l.g33k


People also ask

What is a HATEOAS link?

HATEOAS allows the server to make URI changes as the API evolves without breaking the clients. Above API interaction is possible using HATEOAS only. Each REST framework provides its way of creating the HATEOAS links using framework capabilities.

Should you use HATEOAS?

Using HATEOAS allows an API to clearly define a control logic that is available at the client-side. This enables them to follow links embedded in the API resources instead of having them manipulate URLs. This decouples clients from the URL structure so that changes don't end up hurting integration.

What is HATEOAS example?

Example. A user-agent that implements HTTP makes an HTTP request of a REST API through a simple URL. All subsequent requests the user-agent may make are discovered inside the responses to each request. The media types used for these representations, and the link relations they may contain, are standardized.


1 Answers

Links are comprised of two elements: href and rel. The href contains the explicit URL to locate a resource. The rel identifies the relationship between the current resource and the link's resource. The rel should be used to determine what HTTP method is acceptable and how the link should be used.

The following is a quote from RESTful Web Services Cookbook section 5.4:

A link relation type conveys the role or purpose of a link. Once clients and servers agree on the meaning of these types, clients can find and use URIs from links.

For example, edit is a standard link relation that has explicit details including details around using GET, PUT, POST, DELETE.

Link relations can be extended and you can add your own.

like image 151
mikehwang Avatar answered Oct 22 '22 12:10

mikehwang