2013-07-22 2 views
2

개발하고자하는 API에 대해 전체 Layer3/HATEOS/RESTful/HAL 문제를 조사하고 있습니다.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}&region=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" } 
    ] 
} 

}

답변

1

이 조기 최적화 것 같은 느낌이 든다. 확실히 클라이언트 프로세싱 복잡성을 위해 페이로드 크기를 절대로 거래하지 않을 것입니다. 특히 REST API를 사용하면 HTTP 1.1 zip을 압축 할 수 있습니다.

이 "효율적인 접근 방식"의 이점을 실제로 측정 해 봤습니까? 내 생각에이 접근법은 모든 것을 전송하는 속도가 느려지 게 될 것입니다!

관련 문제