REST13. 응답
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/
xml;charset=utf-8
!
<발표자>
<아이디>kangwoo</아이디>
</발표자>
Plain Old XML over HTTP
HTTP Client HTTP Server
Object
Dispatcher
Dispatcher
Object
Server ApplicationClient Application
26. Remote Procedure Call
주문 서비스
주문 하다()
주문을 확인하다()
주문을 변경하다()
주문을 취소하다()
주문 아이템 추가하다()
POST /주문/주문하다
GET /주문/주문확인하다?아이디={주문아이디}
POST /주문/주문변경하다
POST /주문/주문취소하다.
POST /주문/{주문아이디}?action=주문취소
29. Uniform Interfaces
• Create -> POST
• POST /주문
• Read -> GET
• GET /주문/{주문번호}
• Update -> PUT
• PUT /주문/{주문번호}
• Delete -> DELETE
• DELETE /주문/{주문번호}
30. GET 을 이용한 자원 보기
GET /주문/1234
200 OK
<주문>
…
</주문>
http://콩다방/주문/1234
고객 콩다방
500 Internal Server Error
404 Not Found
ERRORGET
31. HTTP Status Code
• 1xx (조건부 응답)
• 2xx (성고)
• 3xx (리다리렉션 완료)
• 4xx (요청 오류)
• 5xx (서버 오류)
출처 : http://ko.wikipedia.org/wiki/HTTP_상태_코드
32. POST 를 이용한 자원 생성
POST /주문
<주문>
…
</주문>
201 Created
Location http://콩다방/주문/1234
http://콩다방/주문
http://콩다방/주문/1234
고객 콩다방
500 Internal Server Error
400 Bad Request
ERRORCREATE
33. PUT 을 이용한 자원 수정
PUT /주문/1234
<주문>
…
</주문>
200 OK
OR
204 No Content
http://콩다방/주문/1234
고객 콩다방
500 Internal Server Error
409 Conflict
ERRORUPDATE
404 Not Found
35. DELETE 를 이용한 자원 삭제
DELETE /주문/1234
200 OK
OR
204 No Content
http://콩다방/주문/1234
고객 콩다방
500 Internal Server Error
405 Method Not Allowed
ERRORDELETE
404 Not Found
38. 커피를 주문하기
POST /주문 HTTP/1.1
Host: 콩다방
Content-Type: application/xml
Content-Length: 1818
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
</주문>
HTTP/1.1 201 Created
Content-Type: application/xml
Content-Length: 1818
Date:몰라
Location: http//콩다방/주문/1234
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
<status>결제 대기중</status>
</주문>
요청 응답
40. if (status == “결제 대기중”) {
Button 결제버튼 = new Button(“결제”, “http://콩다방/결제/1234”);
Button 변경버튼 = new Button(“변경”, “http://콩다방/변경/1234”, “POST”);
Button 취소버튼 = new Button(“취소”, “http://콩다방/결제/1234”, “DELETE”);
화면.add(결제버튼);
화면.add(변경버튼);
화면.add(취소버튼);
}
앱 개발자의 관점
결제
대기중
결제
주문 변경
주문 취소
43. 결제 대기중
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 1818
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
<status>결제 대기중</status>
<links>
<link href=“http://콩다방/결제/1234” rel=“payment”>결제</link>
<link href=“http://콩다방/주문/1234” rel=“update”>주문 변경</link>
<link href=“http://콩다방/주문/1234” rel=“cancel”>주문 취소</link>
</links>
</주문>
요청
응답
GET /주문/1234 HTTP/1.1
Host: 콩다방
44. 결제 완료
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 1818
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
<status>결제 완료</status>
<links>
<link href=“http://콩다방/주문/1234” rel=“update”>주문 변경</link>
<link href=“http://콩다방/주문/1234” rel=“cancel”>주문 취소</link>
</links>
</주문>
요청
응답
GET /주문/1234 HTTP/1.1
Host: 콩다방
45. 음료 준비중
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 1818
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
<status>음료 준비중</status>
</주문>
요청
응답
GET /주문/1234 HTTP/1.1
Host: 콩다방
47. EntityTag
GET /주문/1234 HTTP/1.1
Host: 콩다방
HTTP/1.1 200 OK
Content-Type: application/vnd.cafe.order+xml
Content-Length: 1818
ETag: “123456789abcdef”
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
<status>결제 대기중</status>
</주문>
요청
응답
48. EntityTag
GET /주문/1234 HTTP/1.1
Host: 별다방
IF-None-Match: “123456789abcdef”
HTTP/1.1 204 No Content
요청
ETag가 동일할때
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 1818
ETag: “123456789abcdef”
!
<주문>
<items>
<item>
<name>아메리카노</name>
<size>제일큰거</size>
</item>
</items>
ETag가 다를때
49. EntityTag
PUT /주문/1234 HTTP/1.1
Host: 콩다방
IF-Match: “123456789abcdef”
!
<주문>
…
</주문>
HTTP/1.1 204 No Content
ETag: “123456789abcdef”
요청
응답 (수정 성공)
HTTP/1.1 412 Precondition Failed
응답 (수정 실패)
51. 주문 변경
POST /주문/1234 HTTP/1.1
Host: 콩다방
!
<주문>
<items>
<item>
<name>아이스크림 와플</name>
<size>제일큰거</size>
</item>
</items>
</주문>
요청