Browser Web ServerGET /index.html HTTP/1.1Host: www.pitt.edu
HTTP/1.1 200 OKContent-Type: text/html
HTTP Request• The HTTP request is sent from the client.
– Identifies the location of a resource.– Uses nouns rather than verbs to denote simple resources.– Specifies the verb, or HTTP method to use when accessing the resource.– Supplies optional request headers (name-value pairs) that provide additional
information the server may need when processing the request.– Supplies an optional request body that identifies additional data to be
uploaded to the server (e.g. form parameters, attachments, etc.)
Standard Set of Methods ● GET - read data and not change it.● PUT - update capabilities● POST - create subordinate resources● DELETE - delete a resource● OPTIONS - ‘What methods are allowed’● HEAD - HTTP header
• The protocol identifies the transport scheme that will be used to process and respond to the request.
• The host name identifies the server address of the resource.• The path and query string can be used to identify and customize
the accessed resource.
protocol host name path to a resource query string
RESTful Application Cycle
Resources are identified by URIs
Clients communicate with resources via requests using a standard set of methods
Requests and responses contain resource representations in formats identified by media types.
Responses contain URIs that link to further resources
Examples of Rest URIsInsert new customer in a system
Read a customer with customer ID
Read all orders with customer ID
JAX-RS is a Java standard API for REST services:
• Services are annotation driven• Provides support for data binding.(JAX-B)• Provides advanced APIs for content negotiation.(@Produces/@Consumes)
SOAP vs. REST: OverviewBoth SOAP and REST are front-end technologies.
SOAP – Simple Object Access Protocol Supports a variety of transports (HTTP, JMS, etc.) and integrates with a variety of web service standards. Typically used to pass contractually structured data between applications. Bound to xml. Uses SOAP envelope and then HTTP (or FTP/SMTP) to transfer the data. Slower performance and scalability is a bit complex. Caching not possible.
REST - Representational State Transfer
Architectural style Simple point-to-point communication using well-established HTTP verbs, protocols, and standards. Supports many different data formats like JSON, XML etc. Performance and scalability, caching. Lightweight, easy to consume. Widely and frequently used.
SOAP vs. REST: Overview
- XML-based protocol - How to access the service and what operations are performed
Broadly consists of:
- Types - Operation - Binding
WSDL- Webservices Description Language
Name of the service
Parameter of the ws
targetNamespace, default and other namespaces
WSDL Example- contd. Define binding
Connect port and binding
Restful Webservices● A RESTful Web service follows four basic design principles:
o Uses HTTP methodso Be stateless as far as possibleo Expose directory/folder structure-like URIo Transfer XML, JSON, or both
Java API for RESTful Web Services (JAX-RS)vs Spring MVCSome Guidelines for choosing your solution:• Both JAX-RS and Spring MVC can produce REST services.• Spring MVC is a web application framework that can be used as service framework.