2
我調查了整個三層/ HATEOS/REST風格/ HAL的事情,我們正在尋找開發一個API。REST/HATEOAS:就是一種模板的restul鏈接可接受的方法
我們將暴露數據的列表可以通過這些鏈接可以臃腫。模板鏈接不是一個想法,這會被稱爲什麼?我似乎無法找到任何提及,如果這不是一個好方法,爲什麼?
以一個假想的假期搜索API的入口點可以提供目的地和出發機場允許用戶開始使用一個或另一個搜索列表。
下面是類似的更有效的方法嗎? (鬆散地基於HAL)如果不是爲什麼?
{
"_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" }
]
}
}