Hypertext Application Language

Hypertext Application Language (HAL) is an Internet Draft (a "work in progress") standard convention for defining hypermedia such as links to external resources within JSON or XML code (however, please note that the latest version of HAL Internet-Draft expired on November 12, 2016.). The standard was initially proposed in June 2012 specifically for use with JSON[1] and has since become available in two variations, JSON and XML. The two associated MIME types are media type: application/hal+xml and media type: application/hal+json.[2]

HAL was created to be simple to use and easily applicable across different domains by avoiding the need to impose any requirements on how the project be structured. Maintaining this minimal impact approach, HAL has enabled developers to create general-purpose libraries which can be easily incorporated on any API that uses HAL.

APIs that adopt HAL simplify the use of open source libraries and make it possible to interact with the API using JSON or XML. The alternative would be having to develop a proprietary format which in turn forces developers to learn how to use yet another foreign format.[3]

Convention

HAL is structured in such a way as to represent elements based on two concepts: Resources and Links. Resources consist of URI links, embedded resources, your standard data (be it JSON or XML), and non URI links. Links have a target URI, as well as the name of the link (referred to as 'rel'), as well as optional properties designed to be mindful of deprecation and content negotiation.[3]

Example

General Resource

{
  "_links": {
    "self": {
      "href": "http://example.com/api/book/hal-cookbook"
    }
  },
  "id": "hal-cookbook",
  "name": "HAL Cookbook"
}

Embedded resource

{
  "_links": {
    "self": {
      "href": "http://example.com/api/book/hal-cookbook"
    }
  },
  "_embedded": {
    "author": {
      "_links": {
        "self": {
          "href": "http://example.com/api/author/shahadat"
        }
      },
      "id": "shahadat",
      "name": "Shahadat Hossain Khan",
      "homepage": "http://author-example.com"
    }
  },
  "id": "hal-cookbook",
  "name": "HAL Cookbook"
}

Collections

{
  "_links": {
    "self": {
      "href": "http://example.com/api/book/hal-cookbook"
    },
    "next": {
      "href": "http://example.com/api/book/hal-case-study"
    },
    "prev": {
      "href": "http://example.com/api/book/json-and-beyond"
    },
    "first": {
      "href": "http://example.com/api/book/catalog"
    },
    "last": {
      "href": "http://example.com/api/book/upcoming-books"
    }
  },
  "_embedded": {
    "author": {
      "_links": {
        "self": {
          "href": "http://example.com/api/author/shahadat"
        }
      },
      "id": "shahadat",
      "name": "Shahadat Hossain Khan",
      "homepage": "http://author-example.com"
    }
  },
  "id": "hal-cookbook",
  "name": "HAL Cookbook"
}
gollark: ȟ̃̃ë̛́̉l̂̀̽p͗͋̐ ̉͌͘m̛̆͂é́̑ ̓̓́p̈̂͌ö́͂̚t̛̆̓ẩ̕t̅̋̚O̔̀̚Ŝ͋͘ ̓͒̋ȉ͒̔s̃͆̑ ̅̂͠c͗̎͊õ̎̕m̄́͠i͋͒͘n̂͊̊g̒̽̑
gollark: PotatOS. PtaMO>. otatOS.otatOS PttO. ottSt PgatO. Pota. PwtatOS. PottOZP~tatOo oatOSs(PPtatS. PtctOS. Poat+S.PotaO. PotwtOS. PotayS* Potat8(tatS. Pooat.otatOy. Pa]S. PotaOSPoaBS.mPpaOS. Pot{CS.otaOS.Pot$tOSTPotOS. PotaAS. ott
gollark: Iptal poBtOS. InsallptatO'.Install pqatOS^Inta/l potaOR. Install potatOSrstall otatS. nstall potaj.
gollark: Tis mesage hs ha lsy compressio,pplied i i.>This>mssge 8aS ha losy cmpressi\#pie oit. T,s Ossgehs h_loss compres#iozappl-e& toiThi mssae asIad="osy comprein aplie co it.This Nesage aWha losyNcjpressiog appid to it.
gollark: PotatOS?

See also

References

  1. Kelly, Mike (7 June 2012). "JSON Hypertext Application Language". IETF. Retrieved 16 October 2018.
  2. Richardson, Leonard; Ruby, Mike Amundsen ; foreword by Sam (2013). "7". RESTful Web APIs (First ed.). Sebastopol, CA: O'Reilly. ISBN 978-1-4493-5806-8.
  3. Kelly, Mike (2011-06-13). "HAL - Hypertext Application Language A lean hypermedia type". Retrieved 23 July 2014.


This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.