This document introduces REST.
Explain about what is REST? and advanced REST feature.
It also introduce REST actual implementation with Jersey and REST infrastructure architecture with ESB based on actual delivery experience.
One more interest thing is that it has REST client stub generator & service contract generator design
건축학과 혹은 건축공학과로 진학을 희망하는 고등학생 친구들을 위해 제작한 자료입니다.
2015 WISET 건축 NO 1 _
이인혜(세종대 대학원 건축학과), 박미영(세종대 건축학과), 주아진(동국대 경찰행정학과)
이은혜(시흥매화고), 심진하(시흥매화고), 김성은(해성여고), 박지연(해성여고)
우리는 피피티를 만드는데 너무 많은 시간을 쓰고 있습니다.
피피티는 잘 해야 하는 것이 아니라 기본만 하면 되는 것입니다.
피피티로 날밤새지 않고, 피피티로 무시받지 않는 방법!
프레젠테이션 기획, 제작, 발표까지, 그 기본을
야매피티가 알려드립니다.
2015.10.04 야매피티 version 2.0 update
2017.05.24 야매피티 version 3.0 update
[TechDays Korea 2013]에서 발표한 "ASP.NET Web API를 이용한 오픈 API 개발" 세션의 발표 자료입니다.
※ 이 자료는 업로드 시점 대비 오래전 진행한 내용을 다루고 있습니다. 변경된 부분이 있거나 유용하지 않을 수 있으니 참고 부탁드립니다.
REST에 대한 내용을 정리한 PPT 입니다.
많은 내용이 있지만 축약 또는 이해되는 내용만 정리를 하려고 하다보니 빠진 부분이 있을 수 있습니다.
REST는
1. URI와 HTTP Method를 이용해 객체화된 서비스에 접근하는 것.
2. HTTP URI로 잘 표현된, 리소스에 대한 행위를 HTTP Method에 정의 리소스에 내용은 json, xml, yaml 등의 다양한 언어로 정의.
3. 하나의 URI는 하나의 고유한 리소스를 대표하도록 설계된다는 개념.* REST는 표준이 아님 + REST는 프로토콜이 아님.
결론적으로 REST API를 사용하는 궁극적인 목적은
서로 다른 플랫폼(OS, 개발언어)에서 데이터를 주고받기 위해서와 범용 인터페이스(HTTP/URI)를 만들어서 각 API를 독립적으로 배포하기 위함이다.
Kubernetes advanced sheduling
- Taint and tolerant
- Affinity (Node & inter pod)
Learn how to place Pod like (same or different) node, rack, zone, region
4. Agenda REST의 기원 Basic of REST Basic REST example Advanced REST example Advanced REST REST Implementation Reference Architecture of REST REST Stub generator 구현시 고려 사항
5. 1. REST의 기원 웹(HTTP)의 공동 창시자 Roy Fielding의 2000년 박사 논문에 소개 됨. 기존의 웹이 HTTP의 장점을 100% 활용하지 못하고 있음 네트워크 아키텍쳐 (Not a protocol) De facto Standard 오픈 진영(Google ,Amazon) 에 의해서 주도됨
10. 자바스터디 시스템에서 이름이 “bcho”인 사용자 정보를 삭제URI : http://www.javastudy.co.kr/users/bchoMethod : POST <user> <name>조대협</name> <email>bcho@bea.com</email> </user> Resource Action Message URI : http://www.javastudy.co.kr/users/bchoMethod : GET URI : http://www.javastudy.co.kr/users/bchoMethod : PUT <user> <name>조대협</name> <email>bcho@bea.com</email> </user> URI : http://www.javastudy.co.kr/users/bchoMethod : DELETE
14. Unique한 URI 사용으로 인해서 GET에 대해서 웹캐쉬 사용가능 비약적인 성능 향상http://example.org/products/1234 http://example.org/user/scott http://example.org/account/XA123-345 http://example.org/products?category=food 권장 http://example.org/orders/2007/11 권장하지 않는 사용법 http://example.org/ITGKA/XATTY
25. 3. Basic REST example STEP 3. AZA12093계좌에서 ADK31242계좌로 $100를 계좌 이체한다. 계좌 이체 Transaction 이 생성됨 계좌 이체 Transaction Id
26. 3. Basic REST example STEP 4. 하루가 지난후 계좌이체 결과를 조회 계좌 이체 진행중
27. 4. Advanced REST example 이것이 과연 REST? 가장 기초중의 기초, 그럼 진짜 REST는? 앞의 예제에서 누락된 HTTP의 특성 LINK의 누락 Link는 리소스간의 관계를 정의할 수 있다. Link를 통해서 리소스간의 BPM과 같은 Work-flow를 정의할 수 있다. Content-Type의 누락 Input/Output Message Type을 정의할 수 있다.
28. 4. Advanced REST example STEP 1. 사용자가 인터넷 뱅킹 시스템에 로그인을 한다. 로그인 했다고 가정 STEP 2. 사용자 ID로 해당 사용자가 가지고 있는 계좌 목록을 조회한다 Content-Type으로 메세지의 형태를 정의 다음 상태로의 LINK를 제공하여 상태 흐름을 정의 Self descriptive message 구현
43. 5. Advanced REST Conditional GET Web Proxy를 이용하여, 캐슁된 내용이 변경이 되지 않았으면 캐쉬 내용을 재활용하는 기술 서버 성능과 자원사용의 효율성이 비약적으로 높아짐 Resource에 대한 URI가 유일하기 때문에 가능함 Last-Modified 헤더나 ETAG 헤더를 이용하여 구현 가능 ※ Resource마다 Last-Modified 값을 관리해야 함 Conditional GET with Last-Modified Header Client REST GET /partners/UK 200 OK Last-Modified: Sun, 21 Jan 2007 09:35:19 GMT [response] Some time later GET /partners/UK If-Modified-Since: Sun, 21 Jan 2007 09:35:19 GMT 304 Not Modified No content
44. 5. Advanced REST Conditional GET with ETag Client REST GET /partners/UK 200 OK ETag:”some UID” [response] Some time later GET /partners/UK If-None-Match:”some UID” 304 Not Modified No content
45. 5. Advanced REST ETAG/Last Modified를 이용한 동시 Update 방지 Etag나 Last-Modified 헤더 이용 동시에 두 사용자가 하나의 Resource에 업데이트를 하여 데이터가 달라지는 문제를 방지 REST Client1 Client2 GET /party/42 200 OK ETag:”some UID” [response] GET /party/42 200 OK ETag:”some UID” [response] POST /party/42 ETag:”some UID” Update가 끝난후 Etag가 변경됨 POST /party/42 ETag:”some UID” 예전 Etag값으로 Update를 요청했기 때문에 412 에러를 내보냄 412 Precondition not satisfied
46. 6. REST implementation Jersey JSR-311 JAX-RS Reference Implementation (https://jersey.dev.java.net/) 장점 구현이 매우 쉬움 (Annotation 사용) Multiple contents representation (XML,JSON) 지원 단점 Advanced REST의 모든 특징을 수용하기에는 부족함 특징 WAR 형태로 배포됨 JAXB를 이용한 XML2JAVA Binding 사용 (VO를 그대로 사용할 수 있음)
47. 6. REST implementation URI HTTP Method Content-Type URI Content-Type: Input Message Type Content-Type : Output Message Type Read Parameter from Query String http://example.org/resource?search=XX Read Parameter from URI http://example.org/resource/{container}
58. Throttling, Alert, Status 모니터링 기능 제공REST/JSON REST/XML WS XML RPC Protocol Conversion Enterprise Service Bus Handling Cross cutting concern Mediation Logic SLA mgmt & Monitoring PLUG IN PLUG IN REST REST REST Components Business Logic Business Logic
59. 7. Reference Architecture of REST REST with ESB Architecture Consumer http://www.rest.com/social http://www.rest.com/social/users/profile http://openapi.rest.com/social/users/profile http://openapi.rest.com/social /OpenAPI/REST/v1.0 http://www.rest.com/OpenAPI/REST/v1.0/social/users/profile REST Component Enterprise Service Bus Order Resource Security Provider Access Layer Business Resource Local Proxy External Edge Proxy REST Component Common Proxy Party Resource Business Resource Local Proxy Internal Edge Proxy Business Resource Local Proxy REST Component Content Resource /InterAPI/REST/v1.0 http://openapi.rest.com/InterAPI/REST/v1.0/social/users/profile
60. 7. Reference Architecture of REST ESB Architecture for REST Resource Application CCC-Logging Generic Proxy Monitoring Edge Proxy Auditing Mediation Orchestration Logic Common Proxy Transformation Compensation Security Framework OAM SLA Alert Local Proxy Throttling CCC-Exception Handling Ignore Reporting Business Resource Auto retry Human Error handling Components
61. 7. Reference Architecture of REST Mash up in ESB Enterprise Service Bus REST Expose Layer Open API Business Service Local Proxy Service Access Layer REST Business Service Common Proxy Edge Proxy Local Proxy Service Open API Business Service Local Proxy Service REST Mashup Local Proxy Open API
62. 8. REST Stub generator REST의 또다른 문제점 클라이언트 STUB이 없음 (WS는 자동 STUB이 있음) REST 서비스에 대한 메뉴얼을 만들어서 웹에 배포해야함 해결안 REST 소스코드를 자동 분석하여 CLIENT STUB과 메뉴얼을 자동생성 JAX-RS Source Code Parser(Qdox) Client Stub Code Velocity(Code Template) XML (Meta Info) REST API Manual(HTML) XSLT (Style Sheet) Generator Tool Kit
64. 8. REST Stub generator Mapping Rule 1..N 1..1 Resource name Method Overview Endpoint URI Endpoint URI Http method Response type Description Description Method Summary ||Method||EndpointURI||Http Method||Summary|| Input Parameter Use Common Standard Header || headerparam || type || required || description || Path parameter || name || type || description || Query parameter || name || type || required || description || Message payload ||element name || type || multiplicity|| description|| From JAXB code XML Scheme Output Parameter Use Common Standard Header || headerparam || type || required || description || Message payload ||element name || type || multiplicity|| description|| From JAXB code XML Scheme Http response code || Http response code || description || Sample Input Http-method : Endpoint-uri : Http header & values Message Payload Output Http-response code Http header & values Message Payload public void method(@HttpHeader (“x-REST-requestid”)String requestid We will use header with “HeaderConfigVo”will not support @HttpHeader annotation in this phase JAX-RS source code Meta Information
65. 9.구현시 고려사항 REST 아키텍쳐로 접근 프로젝트에서 개발자들이 RPC 형태에 익숙해져 있음 Operation이나Method와 같은 행위 중심으로 설계에서 Resource 중심의 설계 DB설계 고려 Resource 가 DB로 어떻게 Mapping 될것인가에 대한 사전 고려 필요 Primary Key와 ResourceID (URI)간의 연관 관계 고려 Alternative Key (AK) 고려 캐쉬는 양날의 검 웹의 특징을 잘 살리고 성능을 극대화 시킴 Last Modified 시간을 유지해야 함 전문 설계 REST는 표준이 없기 때문에, 내부 표준 전문 구현이 중요 헤더에 어떤 데이타를 넣을것인지 HTTP Response Code를 어떻게 사용할것인지 정의 필요
66. Thank you For more information please visit my blog. http://bcho.tistory.com