Class HateoasResponse

java.lang.Object
com.helixframework.api.contract.HateoasResponse
Direct Known Subclasses:
BatchResponse, ErrorResponse, GenericMessageResponse, HateoasBidiCursorPaginatedResponse, HateoasCollectionResponse, HateoasCursorPaginatedResponse, HateoasOffsetPaginatedResponse, ResponseEnvelope

public abstract class HateoasResponse extends Object
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 Details

    • HateoasResponse

      protected HateoasResponse()
      Constructs a new HATEOAS response with no links.
    • HateoasResponse

      protected HateoasResponse(HalLinks links)
      Constructs a new HATEOAS response with the specified HAL links.
      Parameters:
      links - the HAL links to initialize this response with
    • HateoasResponse

      protected HateoasResponse(Map<String,HalLink> links)
      Constructs a new HATEOAS response with the specified map of links.
      Parameters:
      links - map of link names to HAL links
  • Method Details

    • addLink

      public HateoasResponse addLink(String rel, HalLink link)
      Adds a new link to this response.
      Parameters:
      rel - the name/relation of the link
      link - the HAL link to add
      Returns:
      this response instance
    • addLink

      public HateoasResponse addLink(String name, String href)
      Adds a new link with the specified name and href.
      Parameters:
      name - the name/relation of the link
      href - the href (URL) of the link
      Returns:
      this response instance
    • addLink

      public HateoasResponse addLink(String name, String href, HalLink.HttpMethod method)
      Adds a new link with the specified name, href and HTTP method.
      Parameters:
      name - the name/relation of the link
      href - the href (URL) of the link
      method - the HTTP method for this link
      Returns:
      this response instance
    • addLinks

      public HateoasResponse addLinks(Map<String,HalLink> newLinks)
      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

      public HateoasResponse self(String href)
      Adds a "self" link to this response.
      Parameters:
      href - the href (URL) of the link
      Returns:
      this response instance
    • getLinks

      public HalLinks getLinks()
      Gets the links associated with this response.
      Returns:
      the HAL links for this response