Database Systems Lab. Web2.0 & RESTful Web Services 이규철 충남대학교컴퓨터공학과
Table of Contents I. Web 2.0 II. III. IV. REST Major REST principles RESTful Web Services RESTful Example Related Technologies HTTP JSON AJAX WADL SOAP-based vs. RESTful web services 2
I. Web 2.0 : Overview Web 2.0! Web 태동기 Web 발전기현재의 web 정적인 HTML 페이지의집합 컨텐츠관리시스템에의한동적인웹 포털중심의서비스 분산된 social network 상호작용을통하여성장 Web as Platform Hypertext 에의한단순정보교류 중앙집중적검색및미디어 참여와개방을통한분산, 자율네트워크 3
Web 2.0 이란말의기원 새로운컨퍼런스를위한브레인스토밍세션에서제안된마케팅용어로시작 팀오라일리메모로정리 http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web- 20.html?page=1 2004 년, 2005 년두번의컨퍼런스 버전업이아닌질적변화에대한표현 4
Web 1.0 vs Web 2.0 Berners-Lee, Tim 인터넷사용환경이상호작용과기초적인 HyperLink 구조기반의정적인 HTML 사회적네트워크에중점 컨텐츠제공자가정보를독점 사용자들의참여로콘텐츠와서비스가창조 구독자는정보를소비 분산구조형식으로 다대다 형태 일대다 의형태로상호작용이낮음 5
Web 1.0 vs Web 2.0 Web 1.0 Web 2.0 기본특징미디어로서의웹플랫폼으로의웹 상호작용이낮은정적인웹 기술중심 상호작용성이높은동적인웹 사람중심 컨텐츠구조문서, 페이지꼬리표달린개체 (Tagged Object) 기술 HTML, Active-X 등 Ajax, FLEX, Laszlo, XML, RSS, Atom, Tagging, LAMP 등 정보탐색방법검색및브라우징출판과참여 보안 /OS 종속성 Active X 사용으로인한 OS/ 브라우즈종속성 OS/ 브라우즈와무관 대표브라우즈 IE( 단순뷰어 ) Fire Fox( 유저에의해수정보완 ) 사례 하이퍼링크중심기본사이트 야후의 flickr, 아마존, 네이버지식인, Facebook, Twitter 등 6
Web 2.0 의특징 by Tim O Reilly The Web As Platform: OpenAPI Harnessing Collective Intelligence Data is the Next Intel Inside End of the Software Release Cycle Lightweight Programming Models Software Above the Level of a Single Device Rich User Experiences 7
Web 2.0 Example 8
Web 2.0 Example (cont d) File Sharing: Flickr (Images) YouTube (Videos) Wikipedia (Online Encyclopedia) Blogs Open Source Community (Linux) File Management Tagging Social Websites and Communication: Facebook LastFM Skype StudiVZ LinkedIn, Xing Open Systems: APIs, partly open source allow extensions by users 9
Web 2.0 services Large quantities of data are on the Web The data needs to be managed in an appropriate manner Retrieved, queried, analyzed, transformed, transferred, stored, etc. Technical solutions are needed to enable a true Programmable Web Easy integration of data and services on the Web Desktop apps should work with Web apps Flickr upload, calendar update/sync Web apps should work with the other Web apps LinkedIn can import your Facebook friends Facebook can import your twitter followers Mashups should be enabled Easy service composition The solution can be seen in the form of Web 2.0 services 10
Mashup: Housingmaps.com 11
Mashup: Housingmaps.com (cont d) Housingmaps.com is a mashup created of Craigslist A centralized network of online communities, featuring free online classified advertisements with sections devoted to jobs, housing, personals, for sale, services, community, gigs, résumés, and discussion forums Google Maps The properties described in Craigslist are placed on a map The true power of the applied Web 2.0 approach comes from the fact that it is in no way affiliated with craigslist or Google It consumes Web 2.0 services provided by Craigslist and Google 12
Web APIs & Services Data providers Google maps, Geonames, phone location Microformats (vcard, calendar, review ) Data feeds Functionality Publishing, messaging, payment OpenAPI Protocols / Formats Protocols: REST, SOAP, JavaScript Return Formats: JSON, XML, RDF Web as a Computational Platform 13
II. Related Technologies Todays s set of technologies, protocols and languages used to apply RESTful paradigm: HTTP as the basis XML and JSON for data exchange AJAX for client-side programming (e.g. browser) There exists an attempt to develop WSDL-like definition language for describing RESTful services Web Application Description Language (WADL) 14
HTTP Overview Hypertext Transfer Protocol (HTTP) A protocol for distributed, collaborative, hypermedia information systems A request/response standard typical of client-server computing Currently dominant version is HTTP/1.1 Massively used to deliver content over the Web Web browsers and spiders are relying on HTTP The protocol is not constrained to TPC/IP It only presumes a reliable transport Resources accessed by HTTP are identified by URIs (more specifically URLs), using the http URI schemes 15
HTTP Request-response format Request consists of Request line, such as GET /images/logo.gif HTTP/1.1, which requests a resource called /images/logo.gif from server Headers, such as Accept-Language: en An empty line An optional message body Response consists of Status line which includes numeric status code and textual reason phrase Response headers An empty line The requested content 16
HTTP Request methods HTTP request methods indicate the desired action to be performed on the identified resource: GET Requests a representation of the specified resource. GET should not be used for operations that cause side-effects (problematic with robots and crawlers). Those operations are called safe operations POST Submits data to be processed (e.g., from an HTML form) to the identified resource. The data is included in the body of the request PUT Uploads a representation of the specified resource DELETE Deletes the specified resource. and the other such as TRACE, HEAD, OPTIONS, CONNECT 17
JSON JavaScript Object Notation (JSON) A lightweight computer data interchange format. Specified in Request For Comment (RFC) 4627. Represents a simple alternative to XML A text-based, human-readable format for representing simple data structures and associative arrays (called objects). Used by a growing number of services JavaScript-friendly notation Its main application is in Ajax web application programming. A serialized object or array No namespaces, attributes etc. No schema language (for description, verification) 18
JSON Data types JSON basic data types are Number (integer, real, or floating point) String (double-quoted Unicode with backslash escaping) Boolean (true and false) Array (an ordered sequence of values, comma-separated and enclosed in square brackets) Object (collection of key:value pairs, comma-separated and enclosed in curly braces) null 19
JSON - Example { "firstname": "John", "lastname": "Smith", "age": 25, "address": { "streetaddress": "21 2nd Street", "city": "New York", "state": "NY", "postalcode": "10021" }, "phonenumbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ], "newsubscription": false, "companyname": null } 20
AJAX - Overview Asynchronous JavaScript and XML (AJAX) A group of interrelated web development techniques used on the client-side to create interactive web applications Web apps can fetch data from the server without refreshing the page AJAX is used to increase interactivity and dynamism of web pages Since the technological base is partially shared AJAX and RESTful services make a good match Enriching Web pages with the data operated through RESTful services 21
AJAX Constituent technologies (X)HTML and CSS Information styling and marking. Document Object Model (DOM) A cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Objects are accessed through JavaScript XMLHttpRequest object Present in all major browsers Method to exchange data between the server and browser in async manner XML or JavaScript Object Notation - JSON Interchange, manipulation and display of data. JavaScript Language which brings all these technologies together 22
WADL Overview Web Application Description Language No real uptake W3C Member Submission Application ( = our Web service) Has resources Resources have HTTP methods Inputs and outputs can contain links to resources WADL focuses on resources and hypertext As opposed to operations (WSDL) 23
WADL Example 24
III. REST REST: REpresentational State Transfer An architectural style to design loosely coupled web applications/services Requests and response are built around the transfer of representations of resources Ph.D dissertation of Roy Thomas Fielding (2000) Architectural Styles and the Design of Network-based Software Architectures Basic principles of REST Use HTTP methods explicitly Be Stateless Expose directory structure-like URIs Transfer XML, JSON or both 25
REST (cont d) Requests : verbs (get this document or delete that record) Verbs describe actions that are applicable to nouns Four verbs for every noun: GET, POST, PUT, DELETE Resources : nouns URIs are the equivalent of a noun The REST language has trillions of nouns for all the concepts Most of the things on web are resources (documents, images,...) REST relies on named resources rather than messages to facilitate loose coupling 26
REST USE HTTP methods explicitly Application Task Create Read Update Delete HTTP Method POST: To send a new data GET: To retrieve a resource from specified URI PUT: To store a resource at specified URI DELETE: To delete a resource Most of the applications use CRUD tasks to manipulate the resources Idempotent methods GET, HEAD, PUT, DELETE, OPTIONS 27
REST Be Stateless Needs to be highly scalable to meet up high performance demands For better response times, server topology may contain cluster of servers with intermediaries for load-balancing failover proxies and gateway Clients need to send complete and independent requests Servers don t need to keep the context or state 28
REST Be Stateless (cont d) Stateful Design Stateless Design 29
REST Expose directory structure-like URIs Universal Resource Identifier (URI) is hierarchal Structure of URI should be straightforward, predictable and easily understandable Representing resources in directory like structure and exposing them as URIs is very intuitive Rooted at single path, branches to represent sub-paths e.g. http://www.myservice.org/discussion/{year}/{month}/{day}/{topic} Humans and machines can easily generate structured URIs based on rules/patterns 30
REST Resource as URIs (cont d) Response can contain links to resources instead of embedding them URIs should be static (as much as possible) which allows for bookmarking Some additional guidelines: Hide the Server-side scripting technology file extensions, if any, so you can port to something else without changing the URIs Keep everything lowercase Substitute spaces with hyphens or underscores Avoid query strings as much as possible 31
REST Transfer XML, JSON or both MIME-Type JSON XML XHTML Content-Type application/json application/xml application/xhtml Services can offer content in different data formats using MIMEtypes Clients can use MIME types and HTTP Accept header to get the content in their desired format (content negotiation) 32
IV. SOAP-based vs. RESTful: 서비스구조 SOAP-based web services RESTful web services 33
SOAP-based vs. RESTful: 서비스기술 34
WS-* vs. REST: A quick comparison WS-* listentries() addentry() getentry() deleteentry() updateentry() collection service RESTful listentries() addentry() getentry() deleteentry() updateentry() collection entry entry entry 35
WS-* vs. REST: A quick comparison (cont d) A collection can be for example a news publication blog, list of employees, etc. A SOAP service (WS-*) has a single endpoint that handles all the operations It has to have an application-specific interface A RESTful service has a number of resources (the collection, each entry) The operations can be distributed onto the resources and mapped to a small uniform set of operations WS-* stands for a variety of specifications related to SOAP-based Web Services. 36
SOAP-based vs. RESTful: 서비스사례 SOAP-based web services RESTful web services 37