
REST 는 원격 데이터를 조회, 수정하는 웹서비스에서 널리 활용되는 Architectural Style이다. REST 규약을 따르는 API는 더욱 성숙한 API로 여겨진다. REST API는 쉽고, 유연하며 상호운용성을 제공하기 때문이다.
Richardson Maturity Model (RMM)은 API가 REST의 규약을 따르는 정도를 나타네는 4단계의 레벨을 구분하는 모델이다.
각 단계를 구분하는 세가지 기준은 다음과 같다.
- URI
- HTTP Methods
- HATEOAS (Hypermedia).
Level-0 : Swamp of POX (Plain Old XML)
- 서비스 전체에 하나의 URI만 제공한다.
- POST로 조회, 등록, 수정, 삭제를 다 처리하는 경우
- e.g. SOAL, XML-RPC-based application
<!-- Query employee data for a given employee last name Request: Use of a single URI for all actions POST /employeeData HTTP/1.1 --> <empRequest lastName = "jones"/> <!-- Response: Success status with 3 employee records retrieved HTTP/1.1 200 OK --> <empList> <emp firstName = "Dean"> <empId = "232"/> <joinDate = "2010-01-04"/> </emp> <emp firstName = "Mark"> <empId = "1129"/> <joinDate = "2014-06-05"/> </emp> <emp firstName = "Lucy"> <empId = "2132"/> <joinDate = "2017-03-08"/> </emp> </empList>
Level-1 : Resource-Based Address/URI
- 도메인 별로 다른 URI를 제공
- POST로 조회, 등록, 수정, 삭제를 다 처리
<!-- Request: Every employee is accessible by a unique URI, with employee ID POST /employeeData/2132 HTTP/1.1 --> <!-- Response: Success status with 1 employee record retrieved HTTP/1.1 200 OK --> <emp firstName = "Lucy"> <empId = "2132"/> <joinDate = "2017-03-08"/> </emp>
Level-2 : HTTP Verbs
- GET, POST, PUT, and DELETE 와 같은 HTTP Methods의 적절한 활용
- 응답 값에 데이터의 처리에 관한 내용 X
- 에러에 대한 적절한 응답 제공
<!-- Request: Query uses the appropriate GET command GET /employeeData?empId=2132 HTTP/1.1 --> <!-- Response: Success status with 1 employee record retrieved HTTP/1.1 200 OK --> <emp firstName = "Lucy"> <empId = "2132"/> <joinDate = "2017-03-08"/> </emp>
Level-3 : HyperMedia/HATEOAS
- 가장 성숙한 REST API 단계
- 특별한 명세 없이 API 통신만으로 하이퍼미디어에 대한 링크 제공
<!-- Request: Response contains direct access link to resource GET /employeeData?firstName=Lucy HTTP/1.1 --> <!-- Response: Success status with direct link to 1 employee record retrieved HTTP/1.1 200 OK --> <emp firstName = "Lucy"> <empId = "2132"/> <joinDate = "2017-03-08"/> <link url = "/empData/2132"/> </emp>