Skip to content

Instantly share code, notes, and snippets.

@hjr3
Created December 3, 2012 08:52
Show Gist options
  • Save hjr3/4193718 to your computer and use it in GitHub Desktop.
Save hjr3/4193718 to your computer and use it in GitHub Desktop.
Example of HAL+json using truck as an example

Examples of HAL+json API calls for a truck

Get Trucks

GET /trucks HTTP/1.1
Host: api.example.com
Authorization: Basic username:password
Accept: application/hal+json


HTTP/1.1 200 OK
Date: Mon, 20 Jun 2011 21:15:00 GMT
Content-Type: application/hal+json
Etag: 372b753d68c06990ea22b04b9c9fd4f8

{
   "_links":{
      "self":{
         "href":"/trucks"
      },
      "http://example.com/rels/truck":[{
         "href":"/trucks/1",
      },
      {
         "href":"/trucks/2",
      },
      {
         "href":"/trucks/3",
      }]
   }
}

Get Single Truck

GET /trucks/1 HTTP/1.1
Host: api.example.com
Authorization: Basic username:password
Accept: application/hal+json


HTTP/1.1 200 OK
Date: Mon, 20 Jun 2011 21:15:00 GMT
Content-Type: application/hal+json
Etag: 232b753d68c0450ea22b04b9c9fc4f8

{
   "_links":{
      "self":{
         "href":"/trucks/1"
      }
   },
   "year": 1967,
   "make":"Ford",
   "model":"Mustang"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment