Skip to content

Links and Templates

C.A.B edited this page Nov 30, 2017 · 1 revision

The link and template elements have the same structure and syntax. The only difference between them is the template includes the field "template" set to true. Also the href of the template element may be in the format of URI Template.

Parameters

Both link and template elements take 2 required and 4 optional parameters followed by Closure.

parameter default value description
rel The relation name of the link
href The href URL according to Different forms of URLs page
params '' The query parameters appended to the href URL
locale null The Locale for the content this link points to. The value null means the current server Locale
type 'application/hal+json' The MIME type of the content this link points to
title null The title field to label the link in UI. Value null means do not include this field at all

Optional parameters can be set from within the Closure as well.

Examples

Follow are some examples of the legal links

JSON view fragment Resulting JSON fragment
link ('servlet', '/') "_links": {... "servlet":{"href":"https://github.com/C06A", "type":"application/hal+json", "locale":"en_US"}
link ('file', '/getFile') { "type":"application/octal-stream" } "_links": {... "file":{"href":"https://github.com/C06A/getFile", "type":"application/octal-stream", "locale":"en_US"}
template ('servlet', '{/href}') "_links": {... "servlet":{"href":"https://github.com/C06A{/href}", "type":"application/hal+json", "locale":"en_US","template":true}

In all examples the _links will include the self link and potentially other links before and after one in the table.

Clone this wiki locally