Lecture Note

Report
RESTful Web Service
2014년 12월
한연희
[email protected]
http://link.koreatech.ac.kr
REST – Definition and Motivation
 REST (Representational State Transfer)
– 웹을 기반으로 하는 대규모 네트워크 시스템 설계 및 구현을 위
한 일종의 원칙들의 모음
– 2000년 Roy Fielding의 박사 학위 논문에서 처음 제안.
• 제목: Architectural Styles and the Design of Network-based
Software Architectures
• http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
 최근 REST에 대한 인식 변화
– 기존 방식인 SOAP, XML-RPC 등을 대치하는 웹 서비스 (Web Service)
구현 방식
2
Why is it called
“Representational State Transfer?”
 “Web” is a REST system!
State
n
GET
http://www.google.com
Representation
a link
selection
html/xml/json
State
n+1
a link
selection
google
GET
https://www.google.co.kr/search?q=IoT
Representation
html/xml/json
State
n+1
a link
selection
GET
https://www.facebook.com/nest
facebook
Representation
State
n+2
html/xml/json
3
REST is Not a Standard!
 REST is not a standard
– You will not see the W3C REST specification.
 REST is just a design pattern
– You can design your Web services according to its rules.
 REST uses standards:
– HTTP
– URL
– XML/HTML/JSON/RSS/GIF/JPEG/etc. (Resource
Representations)
– text/xml, text/html, image/gif, image/jpeg, etc. (Resource
Types, MIME Types)
4
REST’s Key Abstraction: Resources
 Any information that can be named can be a resource
– Document, Image, Service (e.g. Today's weather in NY) and
so on…
 Identified by URI
– http://weather.com/ny
 Represented by a standard format
–
–
–
–
–
html
xml
json
rss
…
[URI]
http://weather.com/ny
Resource
NY’s
Weather
[HTML]
<!DOCTYPE html>
<html>
<body>
<temperature>
31.5
</temperature>
</body>
5
</html>
REST Generic Interface
 CRUD/HTTP
– 전체 시스템은 단지 다음 4개의 명령을 사용해서만 동작
애플리케이션 작업
HTTP 명령
Create (생성)
POST
Read (읽기)
GET
Update (갱신)
PUT
Delete (삭제)
DELETE
GET http://wisefree.com/employee 전체 직원 명단을 얻어 온다.
POST http://wisefree.com/employee/603045 특정 직원의 자세한 정보를 생성한다.
GET http://wisefree.com/employee/603045 특정 직원의 자세한 정보를 얻어온다.
PUT http://wisefree.com/employee/603045 특정 직원의 해당 정보를 갱신한다.
DELETE http://wisefree.com/employee/603045 특정 직원의 해당 정보를 삭제한다.
[Note] http://wisefree.com/employee?id=603045 – (X)
6
REST Web Service Design
 Resources
– 제공하려고 하는 자원(리소스, Resource)은 무엇인가?
 Representation
– 지원할 Content-type은 어떤 것들이 있는가?
• XML, JSON, RSS, …
 Operation
– 지원할 연산은 어떤 것들이 있는가?
• GET/POST/PUT/DELETE
 Description
– 별도의 웹 페이지(?)
– RSDL (RESTful Service Description Language)
7
REST vs. RPC (Remote Procedure Call) style
 REST vs RPC-style (Java RMI, CORBA, DCOM, SOAP…)
8
REST Design Example
 Airline Reservation Service: Approach 1
– “Press 1 for Premier, Press 2 for…“
Premier
Customer
Representative
Premier Members
Airline Reservations
Answering
Machine
F.F.
Customer
Representative
Frequent Flyer Members
Regular
Customer
Representative
Regular Members
9
REST Design Example
 Airline Reservation Service: Approach 2
– “Telephone Numbers are Cheap! Use Them!”
1-800-Premier
Premier
Customer
Representative
1-800-Frequent
F.F.
Customer
Representative
1-800-Reservation
Regular
Customer
Representative
Premier Members
Frequent Flyer Members
Regular Members
10
Web Design – Axiom 0
http://www.kings-air/reservations/premier
client
Premier Members
Premier
Member
Reservation
Service
Frequent
http://www.kings-air/reservations/frequent-flyer
Flyer
client
Reservation
Service
Frequent Flyer Members
http://www.kings-air/reservations/regular
client
Regular Members
Regular
Member
Reservation
Service
11
REST Design - Advantages
 The different URLs are discoverable by search engines.
 Easy to understand what each service does
– simply by examining the URL.
 No need to introduce rules.
– Just CRUD is all of rules
– "What you see is what you get.“
 Consistent with Axiom 0.
12
RESTful Open API Example
 Twitter
– Retrieving “Follower Information” using HTTP GET
• https://api.twitter.com/1.1/followers/ids.json?cursor=1&screen_name=sitestreams&count=5000
 {11221722, 23428412, …}
13
RESTful Open API Example
 Facebook
(https://developers.facebook.com/tools/explorer)
14
RESTful Open API Example
 NAVER
– Retrieving “벤허 영화 정보” using HTTP GET
• http://openapi.naver.com/search?key=test&query=벤허
&display=10&start=1&target=movie
15
Government 2.0 & Open API
 서울 열린 데이터 광장 (http://data.seoul.go.kr/)
16
Government 2.0 & Open API
 서울 열린 데이터 광장 (http://data.seoul.go.kr/)
17
Government 2.0 & Open API
 일반 시민들이 직접 공공데이터를 활용해 만든 앱들
18
Open API Statistics
Source (2012): Blog - Innotribe
(http://petervan.files.wordpress.com/2012/07/apibillionaires.png)
19
Resources ( Things)
URLs
Generic Operations
20
인식의 발전
21
Basic GET Request and IoT
22
Advanced GET Request and IoT
Subscribe & Notify (Push)
23
웹(인터넷)+IoT 기술 발전방향
“웹은 기술적이라기 보다는 사회적인 창조에 가깝다.
나는 기술적인 장난감이 아니라 사람들이 함께 일함에
도움을 주는 것 같은 사회적인 효과를 위해 웹을 디자인했다.
웹의 궁극적인 목적은 우리의 거미줄 같은 생활을 지원하고
향상시키는 데 있다.” – Tim Berners-Lee
24

similar documents