Upload
manuel-correa
View
703
Download
14
Embed Size (px)
DESCRIPTION
Restful Web Services IntroductionEnterprise IntegrationUniversity of Georgia
Citation preview
byManuel Correa
RestFul Web ServicesRestFul Web Services
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?
What are RestFul Web Services?What are RestFul Web Services?
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
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
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...
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?
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
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
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
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
<?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
Application/xml Application/json Applicaton/text Multipart/form-data
...
Restful Response Output typesRestful Response Output types
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/
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
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
Jersey: Java Framework that implements JAX-RS
Servlet base framework
https://jersey.dev.java.net/
Restful implementation in JavaRestful implementation in Java
NetBeans 6.8 Apache tomcat 6 Jersey and JAX-RS Application demo: Stocks information
RestFul Web Services - DEMORestFul Web Services - DEMO
DEMO
RestFul Web ServicesRestFul Web Services
Questions ?
RestFul Web ServicesRestFul Web Services