Restfulwebservices 130929131145 Phpapp02
Restfulwebservices 130929131145 Phpapp02
Webservices
Mohammed
Luqman Shareef
2
www.luqmanshareef.com 04/29/20
Agenda
• Introduction to Webservices
• SOAP based webservices
• RESTful webservices
• Implementation of RESTful webservices
• SOAP vs. REST
• Why SOAP?
• Why REST?
• Q&A
3
www.luqmanshareef.com 04/29/20
What is a webservice?
• There are too many definitions.
• Most of them are very specific to SOAP based services, and consider
WSDL and UDDI as its integral parts, like
▫ “Web service is a standard way of integrating Web-based applications
using the XML, SOAP, WSDL and UDDI open standards over an Internet
protocol backbone. ”
www.luqmanshareef.com 2010-02-08
www.luqmanshareef.com 04/29/20
www.luqmanshareef.com 04/29/20
HTTP Header
SOAP Envelope
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
<env:Body>
<v:GetProduct xmlns:v="http://vendorX.com/">
<v:ProdId>X123</v:ProdId>
<v:Name>Hard Drive</v:Name>
</v:GetProduct>
</env:Body>
</env:Envelope>
7
www.luqmanshareef.com 04/29/20
www.luqmanshareef.com 04/29/20
HTTP Protocol
• Lets use standard HTTP protocol.
www.luqmanshareef.com 04/29/20
RPC vs REST
www.luqmanshareef.com 04/29/20
RPC
REST
www.luqmanshareef.com 04/29/20
Benefits
Server side Client side
> Uniform Interface > Easy to experiment in browser
> Cacheable > Broad programming language support
> Scalable > Choice of data formats
> Easy failover > bookmarkable
12
www.luqmanshareef.com 04/29/20
* Services that do not conform to the above required contstraints are not strictly
RESTful web services.
13
www.luqmanshareef.com
Method Resource
Response
HTTP/1.1 200 OK
Date: Tue, 09 Feb 2010 11:41:20 GMT
Server: Apache/1.3.6
Content-Type: application/xml; charset=UTF-8
www.luqmanshareef.com 04/29/20
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
@Path("/employees/{pid}")
public class Product{
@GET
@Produces("text/xml")
public String getProduct(@PathParam(“pid") String pId) {
...
…
}
}
15
www.luqmanshareef.com 04/29/20
The @GET annotation is a request method designator and corresponds to the similarly named HTTP
@GET method. The Java method annotated with this request method designator will process HTTP GET
requests. The behavior of a resource is determined by the HTTP method to which the resource is
responding.
The @POST annotation is a request method designator and corresponds to the similarly named HTTP
@POST method. The Java method annotated with this request method designator will process HTTP POST
requests. The behavior of a resource is determined by the HTTP method to which the resource is
responding.
The @PUT annotation is a request method designator and corresponds to the similarly named HTTP
@PUT method. The Java method annotated with this request method designator will process HTTP PUT
requests. The behavior of a resource is determined by the HTTP method to which the resource is
responding.
@DELETE The @DELETE annotation is a request method designator and corresponds to the similarly named HTTP
method. The Java method annotated with this request method designator will process HTTPDELETE
requests. The behavior of a resource is determined by the HTTP method to which the resource is
responding.
16
www.luqmanshareef.com 04/29/20
The @PathParam annotation is a type of parameter that you can extract for use in your resource
@PathParam class. URI path parameters are extracted from the request URI, and the parameter names
correspond to the URI path template variable names specified in the @Path class-level annotation.
The @QueryParam annotation is a type of parameter that you can extract for use in your resource
@QueryParam
class. Query parameters are extracted from the request URI query parameters.
The @Consumes annotation is used to specify the MIME media types of representations a resource
@Consumes can consume that were sent by the client.
The @Produces annotation is used to specify the MIME media types of representations a resource
@Produces can produce and send back to the client, for example, "text/plain".
17
www.luqmanshareef.com 04/29/20
www.luqmanshareef.com 04/29/20
www.luqmanshareef.com 04/29/20
www.luqmanshareef.com 04/29/20
Why REST?
• Exposing a public API over the internet to handle CRUD operations on data.
• REST is particularly useful for restricted-profile devices such as mobile and PDAs for
which the overhead of additional parameters like headers and other SOAP elements
are less.
21
www.luqmanshareef.com 04/29/20
Why SOAP?
• SOAP is not only for Web. It has its own protocol.
• SOAP Exposes application logic (not data) as service. Exposes named operations.
• SOAP Web services are useful in handling asynchronous processing and invocation.
• Most real-world applications are not simple and support complex operations, which require
conversational state and contextual information to be maintained. With the SOAP
approach, developers need not worry about writing this plumbing code into the application
layer themselves.
22
www.luqmanshareef.com 04/29/20
WSDL 2.0
• WSDL 2.0 is tailored for SOAP-based Web services
• However, HTTP binding in WSDL 2.0 allows for good description of HTTP services
▫ <binding name="HttpBinding" interface="m:GetTemperature"
type="http://www.w3.org/2005/08/wsdl/http">
<operation ref="m:location" whttp:method="GET"
whttp:location="{country}/{city}"/>
</binding>
<weather xmlns="…">
<temperature>23</temperature>
</weather>
www.luqmanshareef.com 2010-02-08
Questions?
24
www.luqmanshareef.com 2010-02-08