Interface LinkableResource


@ConsumerType public interface LinkableResource
An interface to be implemented by all resources that should be accessible directly via a URL (and therefore can be linked to from another resource).

You can make your HalApiInterfaces extends this interface directly, and doing so will make it possible for clients to extract the resource link and URL from a client proxy by calling createLink(). This can be useful if the client need to select one of multiple links based on the link properties, or do other processing that requires the knowledge of the URLs.

You may want want to keep the option of having certain small resources only be available as embedded resource, and not let your clients know that they can also fetch an it directly through an URL. In that case, you would not make your interface extend LinkableResource, but only implement it in the server-side implementation class.

If you don't implement this interface in your server-side implementation of a HAL API interface, then that resource cannot be rendered on its own, but only be embedded (and you must implement EmbeddableResource instead).

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    io.wcm.caravan.hal.resource.Link
    Create a link to this resource, including meaningful title and name properties where appropriate.
  • Method Details

    • createLink

      io.wcm.caravan.hal.resource.Link createLink()
      Create a link to this resource, including meaningful title and name properties where appropriate. If all required parameters of the resource are set, then the link should have a resolved URI as href property. If some or all required parameters are null, a link with a URI template should be created instead.

      Note that the Link instance doesn't have a relation property, because that is derived from the Related annotation of the method that defines the links to this resource. The same resource can be linked from multiple other resources using different relations, but all links are created on the server side using the same method.

      Returns:
      a Link instance where href, title and name properties are already set as required