I'm investigating the whole Layer3/HATEOS/RESTful/HAL thing for an API we're looking to develop.
We would be exposing lists of data could be bloated by all these links. Wouldn't it be an idea to template the links, what would this be called? I can't seem to find any mention of it, if it's not a good approach, why?
Take a hypothetical holiday search API, the entry point could provide lists of destinations and departure airports allowing the user to start searching using one or the other.
Would something like the following be a more efficient approach? (loosely based on HAL) And if not why?
{
"_links": {
"self": {
"href": "/"
},
"_templates": {
"airport": {
"self": { "href": "/airport/{IATA}" },
"destinations": { "href": "destinations?airport={IATA}" },
"parking": { "href": "/airport/{IATA}/parking" },
"hotels": { "href": "/hotels?airport={IATA}" },
"directions": { "href": "/guides?airport={IATA}" },
"search": [
{ "href": "/search?airport={IATA} title": "default" },
{ "href": "/search?airport={IATA}&type=CITY title": "citybreak" },
{ "href": "/search?airport={IATA}&type=LOW titel": "lowcost" }
]
},
"country": {
"self": { "href": "/destinations/{Code}/" },
"regions": { "href": "/destinations/{Code}/regions" },
"resorts": { "href": "/destinations/{Code}/resorts" },
"airports": { "href": "/destinations/{Code}/airorts" },
"search": { "href": "/search?country={Code}®ion=ANY&resort=ANY" }
}
}
},
"_embedded": {
"airport": [
{ "IATA": "LHR Name": "London Heathrow Airport" },
{ "IATA": "EMA Name": "East Midlands Airport" },
{ "IATA": "NWI Name": "Norwich International Airport" },
{ "IATA": "LTN Name": "London Luton Airport" },
{ "IATA": "STN Name": "London Stansted Airport" },
{ "IATA": "LCY Name": "London City Airport" },
{ "IATA": "LPL Name": "Liverpool John Lennon Airport" },
{ "IATA": "MAN Name": "Manchester Airport" },
{ "IATA": "LGW Name": "Gatwick Airport" }
],
"country": [
{ "Code": "CY Name": "Cyprus" },
{ "Code": "CZ Name": "Czech Republic" },
{ "Code": "ES Name": "Spain" },
{ "Code": "FO Name": "Faroe Islands" },
{ "Code": "GG Name": "Guernsey" },
{ "Code": "GR Name": "Greece" }
]
}
}