Skip to content

Instantly share code, notes, and snippets.

@dschulten
Last active December 18, 2015 00:19
Show Gist options
  • Save dschulten/5696110 to your computer and use it in GitHub Desktop.
Save dschulten/5696110 to your computer and use it in GitHub Desktop.
Possible HAL equivalent to forms
// HAL "form" for single-item-resource. Clients must query OPTIONS for /account
// to ensure they can PUT, POST, DELETE, GET. The profile attribute contains a json-schema
// which can also be requested in other media types from /rels/account.
{
"userName": "Fred",
"realName": "Fred Flintstone",
"password": "yabbadabba",
"_links": {
"self": {
"href": "/account"
}
},
"_embedded": {
"profile": {
"_links": {
"self": { "href": "http://www.example.com/rels/account" }
},
"title": "account",
"type": "object",
"properties": {
"userName": {
"type": "string"
},
"realName": {
"type": "string"
},
"password": {
"type": "string"
},
},
"required": ["userName", "password"]
}
}
}
// HAL "form" for collections.
{
"_links": {
"self": {
"href": "/reviews"
}
},
"_embedded": {
"reviews": [
{
"_links": {
"self": { "href": "/review/126" },
"customer": { "href": "/customer/fred", "title": "Fred Wilson" }
},
"title": "Love it!",
"content": "I love this product. I also bought a Hover Donkey with it.",
"rating": 10
},
{
"_links": {
"self": { "href": "/review/178" },
"customer": { "href": "/customer/tom", "title": "Tom Dee" }
},
"title": "Hate it!",
"content": "My hover donkey choked on it. DO NOT BUY!1!!",
"rating": 0
}
],
"profile": {
"_links": {
"self": { "href": "http://www.example.com/rels/reviews" }
},
"type": "array",
"items": { "$ref": "#/definitions/review" },
"definitions": {
"review": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"content":{
"type": "string"
},
"rating": {
"type": "integer"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment