简体   繁体   中英

Does HATEOAS contemplate hypermedia in the Error Response?

In a Hypermedia-Driven RESTful solution, should I include relevant HATEOAS links in Error responses?

For instance, let's imagine we have a Microservices architecture.

We have FooSvc and BarSvc, where Bar resources are associated in a 1:1 relation with Foo resources, but managed independently (eg we have Projects that we can create just to present them, and then we can decide to Manage a project in our platform).

So, we can try to fetch the Bar resource associated with Foo with id 1 using GET /foo/1/bar (not caring how the request is routed downstream to the BarSvc).

Since there is no such Bar instance created yet, the service will retrieve a 404 response. Should that response include hypermedia links to point out how this can be created (eg a HAL _links field with a link to POST /foo/1/bar )?

Definitely, in fact, RFC7807 - 'Problem Details for HTTP APIs' can help with this, and the most popular frameworks should provide support for it (as for example the Spring HATEOAS library here )

Also, there is a proposed vnd.error mime type for this (further explained in this post ), but it seems it has been superseded by RFC7807 mentioned above, at least Spring deprecated this in favor of the Problem Details approach ( here )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM