RESTFul Web Services - Intro
-
Upload
manuel-correa -
Category
Technology
-
view
698 -
download
14
description
Transcript of RESTFul Web Services - Intro
![Page 1: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/1.jpg)
byManuel Correa
RestFul Web ServicesRestFul Web Services
![Page 2: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/2.jpg)
REst = REpresentation State Tranfer
RestFul is a software architectural style
Stateless client-server architecture
Web Services are resources identify by an URL
e.g: www.mydomain.com/stock/GOOG
What are RestFul Web Services?What are RestFul Web Services?
![Page 3: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/3.jpg)
What are RestFul Web Services?What are RestFul Web Services?
![Page 4: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/4.jpg)
Application descriptionWSDL vs. WADL (Web Application Description Language)
Transport ProtocolSOAP vs. HTTP
Discovery and publishingUDDI vs. The Web (in general any url is a resource)
What are RestFul Web Services?What are RestFul Web Services?Comparison with SOAP Web ServicesComparison with SOAP Web Services
![Page 5: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/5.jpg)
RestFul vs. SOAP debateRestFul vs. SOAP debate
REST SOAP
Use HTTP transport protocol SOAP over HTTP
Point to point communication Designed to distributed systems...
Simpler specification Heavy specification. To much XML flavors
Simple implementation Harder to develop
Any HTTP client will “work” Only SOAP clients
No require client API Must generate a SOAP client
![Page 6: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/6.jpg)
RestFul vs. SOAP debateRestFul vs. SOAP debate
Companies are moving from SOAP web services to RestFul web services
RestFul web services are coming more popular because they are simpler to implement than SOAP
If you know HTTP you know Rest (My claim)...
Everything you can do with restful you can do it with SOAP...
![Page 7: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/7.jpg)
Google Ajax API is now full restful with JSON output
Amazon offers SOAP and Restful interfaces. 80% developers are using REST
Yahoo Restful API to access Yahoo Web Services
ESRI with ArcGIS Server with Map Services (Also support SOAP)
Does anyone knows another company that is using Rest?
Who is using Restful?Who is using Restful?
![Page 8: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/8.jpg)
HTTP: Hyper Text Transport Protocol
HTTP work with two functions: REQUEST and RESPONSE (client-server architecture)
Works over TCP/IP generally
A HTTP resource is identified by an URI
HTTP ReviewHTTP Review
![Page 9: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/9.jpg)
Request header
GET /stocks/GOOG HTTP/1.1Accept application.xmlUser-Agent Mozilla...Accept-Language en-us...[BODY]
Request methods: HEAD, GET, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH
HTTP Review – RequestHTTP Review – Request
![Page 10: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/10.jpg)
Response header
HTTP/1.1 200 OKServer: ApacheContent-type application/xmlContent-length 155Date Sun, 10 Oct 2010...[BODY]
Response codes 1xx: informational. 2Xx: Success. 3XX: redirection. 4XX Client error. 5XX: server error.
HTTP Review – ResponseHTTP Review – Response
![Page 11: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/11.jpg)
Restful methods – Compare with SQLRestful methods – Compare with SQL
Action SQL HTTP(Rest)
Create Insert PUT
Read Select GET
Update Update POST
Delete Delete DELETE
![Page 12: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/12.jpg)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://research.sun.com/wadl/2006/10">
<doc xmlns:jersey="http://jersey.dev.java.net/" jersey:generatedBy="Jersey: 1.1.4 11/10/2009 05:36 PM"/>
<resources base="http://localhost:8084/RestFulServer/resources/">
<resource path="/stock">
<resource path="/{symbol}">
<param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="symbol" style="template" type="xs:string"/>
<method id="getStock" name="GET">
<response>
<representation mediaType="application/xml"/>
<representation mediaType="application/json"/>
</response>
</method>
<method id="deleteStock" name="DELETE"/>
<method id="putStock" name="PUT"/>
<method id="postStock" name="POST">
<response>
<representation mediaType="application/xml"/>
<representation mediaType="application/json"/>
</response>
..
WADL SpecificationWADL Specification
![Page 13: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/13.jpg)
Application/xml Application/json Applicaton/text Multipart/form-data
...
Restful Response Output typesRestful Response Output types
![Page 14: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/14.jpg)
JSON JSON ( JavaScript Object Notation)( JavaScript Object Notation)
Lightweight inter-change format Language independent Easy for humans and machine to read
“stock”: {"lastestTrade":"2010-10-10T16:29:23.327-04:00","name":"Google Inc.","price":"415.5","symbol":"GOOG","volume":"200"
}
Stock.name = “GOOG”
http://www.json.org/
![Page 15: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/15.jpg)
RESTFul Services◦ JAX-RS 1.0 (JSR 311)◦ Jersey framework
Client side◦ JavaScript (JQuery 1.2)◦ Java (HttpClient)◦ Curl◦ Any software/framework that supports HTTP and XML, JSON as response.
Others technologies (Server Side)◦ Spring Framework 2.5 (Context of the Web Application )◦ Hibernate/JPA (ORM to map the database – Model of the Application)◦ Oracle 10g
RestFul Java APIRestFul Java API
![Page 16: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/16.jpg)
JAX-RS: Java specification for RestFul Web Services (JSR 311)
JAX-RS provides a set of Java annotations that allows you to annotate your POJO and give the Restful behavior
Restful implementation in JavaRestful implementation in Java
Annotation Description
@Path URI description
@GET, @POST, @PUT, @DELETE
Method description. Use of java methods to denote how to acces them
@Produces, @Consumes Define what is produced when a method is invoked. Consumes define what is allow in the input
@PathParam Parameter in the URI. eg. /stock/{symbol}
@QueryParam Parameter /stock/GOOG?hidePrice=true
![Page 17: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/17.jpg)
Jersey: Java Framework that implements JAX-RS
Servlet base framework
https://jersey.dev.java.net/
Restful implementation in JavaRestful implementation in Java
![Page 18: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/18.jpg)
NetBeans 6.8 Apache tomcat 6 Jersey and JAX-RS Application demo: Stocks information
RestFul Web Services - DEMORestFul Web Services - DEMO
![Page 19: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/19.jpg)
DEMO
RestFul Web ServicesRestFul Web Services
![Page 20: RESTFul Web Services - Intro](https://reader033.fdocuments.in/reader033/viewer/2022052412/5596200c1a28ab970e8b48a6/html5/thumbnails/20.jpg)
Questions ?
RestFul Web ServicesRestFul Web Services