Package com.helixframework.api.contract
Class HateoasResponse
java.lang.Object
com.helixframework.api.contract.HateoasResponse
- Direct Known Subclasses:
BatchResponse,ErrorResponse,GenericMessageResponse,HateoasBidiCursorPaginatedResponse,HateoasCollectionResponse,HateoasCursorPaginatedResponse,HateoasOffsetPaginatedResponse,ResponseEnvelope
Represents a base class for creating HATEOAS (Hypermedia as the Engine of Application State)
compliant responses. This class manages the `_links` structure, which contains hypermedia
links in the HAL (Hypertext Application Language) format.
This structure allows embedding resource-related links like self, next, update, etc., into a
response, providing navigation and action metadata for a resource.
The `_links` property is represented by the
HalLinks object, which holds a collection
of link relations and their associated HalLink definitions.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new HATEOAS response with no links.protectedHateoasResponse(HalLinks links) Constructs a new HATEOAS response with the specified HAL links.protectedHateoasResponse(Map<String, HalLink> links) Constructs a new HATEOAS response with the specified map of links. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new link to this response.Adds a new link with the specified name and href.addLink(String name, String href, HalLink.HttpMethod method) Adds a new link with the specified name, href and HTTP method.Adds multiple links from the provided map to this response.getLinks()Gets the links associated with this response.Adds a "self" link to this response.
-
Constructor Details
-
HateoasResponse
protected HateoasResponse()Constructs a new HATEOAS response with no links. -
HateoasResponse
Constructs a new HATEOAS response with the specified HAL links.- Parameters:
links- the HAL links to initialize this response with
-
HateoasResponse
Constructs a new HATEOAS response with the specified map of links.- Parameters:
links- map of link names to HAL links
-
-
Method Details
-
addLink
Adds a new link to this response.- Parameters:
rel- the name/relation of the linklink- the HAL link to add- Returns:
- this response instance
-
addLink
Adds a new link with the specified name and href.- Parameters:
name- the name/relation of the linkhref- the href (URL) of the link- Returns:
- this response instance
-
addLink
Adds a new link with the specified name, href and HTTP method.- Parameters:
name- the name/relation of the linkhref- the href (URL) of the linkmethod- the HTTP method for this link- Returns:
- this response instance
-
addLinks
Adds multiple links from the provided map to this response.- Parameters:
newLinks- map of link names to HAL links to add- Returns:
- this response instance
-
self
Adds a "self" link to this response.- Parameters:
href- the href (URL) of the link- Returns:
- this response instance
-
getLinks
Gets the links associated with this response.- Returns:
- the HAL links for this response
-