Hypertext Application Language

The Hypertext API Language (HAL) is a promising proposal that sets the conventions for expressing hypermedia controls (such as links) with JSON or XML. Currently, this proposal is in the draft stage. It mainly describes two concepts for linking resources:

  • Embedded resources: This concept provides a way to embed another resource within the current one. In the JSON format, you will use the _embedded attribute to indicate the embedded resource.
  • Links: This concept provides links to associated resources. In the JSON format, you will use the _links attribute to link resources.

Here is the link to this proposal: http://tools.ietf.org/html/draft-kelly-json-hal-06. It defines the following properties for each resource link:

  • href: This property indicates the URI to the target resource representation
  • template: This property would be true if the URI value for href has any PATH variable inside it (template)
  • title: This property is used for labeling the URI
  • hreflang: This property specifies the language for the target resource
  • title: This property is used for documentation purposes
  • name: This property is used for uniquely identifying a link

The following example demonstrates how you can use the HAL format for describing the department resource containing hyperlinks to the associated employee resources. This example uses the JSON HAL for representing resources, which is represented using the application/hal+json media type:

GET /departments/10 HTTP/1.1 
Host: packtpub.com 
Accept: application/hal+json 
 
HTTP/1.1 200 OK 
Content-Type: application/hal+json 
 
{ 
  "_links": { 
    "self": { "href": "/departments/10" }, 
    "employees": { "href": "/departments/10/employees" }, 
    "employee": { "href": "/employees/{id}", "templated": true  } 
  }, 
  "_embedded": { 
    "manager": { 
      "_links": { "self": { "href": "/employees/1700" } }, 
      "firstName": "Chinmay", 
      "lastName": "Jobinesh", 
      "employeeId": "1700", 
 
    } 
  },   
  "departmentId": 10, 
  "departmentName": "Administration" 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.41.205