SlideShare una empresa de Scribd logo
1 de 25
By Muhammad Junaid
REST
● REST stands for Representational State Transfer
-Design pattern for developing web services.
● Resource based
● Rest Style:
● Client-server
● Uniform interface
● Stateless
● Cached
● Layered system
● HATEOAS - (Hypermedia As The Engine Of Application State)
By Muhammad Junaid
REST - not a Standard
● But it uses several standards:
o HTTP
o URL
o XML/HTML/GIF/JPEG/etc (Resource Representations)
o text/xml, text/html, image/gif, image/jpeg, etc (Resource Types, MIME Types)
Browser Web ServerGET /index.html HTTP/1.1
Host: www.pitt.edu
HTTP/1.1 200 OK
Content-Type:
text/html
By Muhammad Junaid
Rest API Concepts
 Services exposed to internet for programmatic
access
 Users can be either producers or consumers or
both
 Eg : api.twitter.com
 Data can be returned in the form of XML /JSON
/ etc
 Helps developers to parse data.
 Messages can be exchanged in any kind of
HTTP method
By Muhammad Junaid
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.)
By Muhammad Junaid
Sample Client Requests:
GET /view?id=1 HTTP/1.1 Request Headers
User-Agent: Chrome
Accept: application/json Requested Resource (path and query string)
(no request body)
POST /save HTTP/1.1 Requested Resource (typically no query string)
User-Agent: IE
Content-Type: application/x-www-form-urlencoded Request Headers
name=x&id=2 Request Body (e.g. form parameters)
By Muhammad Junaid
HTTP Response
• The HTTP response is sent from the server.
– Gives the status of the processed request.
– Supplies response headers (name-value pairs) that provide additional
information about the response.
– Supplies an optional response body that identifies additional data to be
downloaded to the client (html, xml, binary data, etc.)
– -HTTP Status codes(1xx, 2xx, 3xx, 4xx, 5xx)
By Muhammad Junaid
Sample Server Responses:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1337
[CRLF]
<html>
<!-- Some HTML Content. -->
</html>
HTTP/1.1 500 Internal Server Error
HTTP/1.1 201 Created
Location: /view/7
[CRLF]
Some message goes here.
Response Status
Response Headers
Response Body (content)
Response Status
Response Header
Response Body
Response Status
By Muhammad Junaid
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
By Muhammad Junaid
Action/Verb
 /orders
 GET - list all orders
 POST - submit a new order
 /orders/{order-id}
 GET - get an order representation
 PUT - update an order
 DELETE - cancel an order
 /orders/average-sale
 GET - calculate average sale
 /customers
 GET - list all customers
 POST - create a new customer
 /customers/{cust-id}
 GET - get a customer representation
 DELETE- remove a customer
 /customers/{cust-id}/orders
 GET - get the orders of a customer
By Muhammad Junaid
A typical HTTP REST URL:
http://my.store.com/fruits/list?category=fruit&limit=20
• 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
By Muhammad Junaid
Representations (MediaType)
 XML
<COURSE>
<ID>CS2650</ID>
<NAME>Distributed Multimedia Software</NAME>
</COURSE>
 JSON
{
“course”: {
“id”: “CS2650”
“name”: “Distributed Multimedia Software”
}
}
By Muhammad Junaid
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
By Muhammad Junaid
Examples of Rest URIs
Insert new customer in a
system
POST
http://www.example.com/customers/12345
Read a customer with
customer ID
GET
http://www.example.com/customers/33245
Read all orders with
customer ID
GET
http://www.example.com/customers/33245/orde
rs
By Muhammad Junaid
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)
By Muhammad Junaid
Jersey
 One of the libraries that implements JAX-RS
, from Oracle.
 Other libraries in the market -* Apache CXF ,
an open source Web service framework .
* RESTeasy , JBoss 's implementation .
* Restlet .
* Apache Wink , Apache Software Foundation Incubator .
* WebSphere Application Server from IBM.
 Choice of library doesn’t matter .
By Muhammad Junaid
Big Picture
By Muhammad Junaid
SOAP vs. REST: Overview
Both 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.
By Muhammad Junaid
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
By Muhammad Junaid
Restful Webservices
● A RESTful Web service follows four basic design principles:
o Uses HTTP methods
o Be stateless as far as possible
o Expose directory/folder structure-like URI
o Transfer XML, JSON, or both
By Muhammad Junaid
Web.xml configuration
<servlet>
<servlet-name>AccountService</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AccountService</servlet-name>
<url-pattern>services/*</url-pattern>
</servlet-mapping>
By Muhammad Junaid
@Path
 Sets the path to base URL + /your_path. The
base URL is based on your application
name, the servlet and the URL pattern from
the web.xml configuration file.
By Muhammad Junaid
@GET, @PUT, @POST,
@DELETE, ...
By Muhammad Junaid
@Produces
 @Produces defines which MIME type is
delivered by a method annotated with
@GET. In
 the example text ("text/plain") is produced.
Other examples would be "application/xml"
 or "application/json"
By Muhammad Junaid
URI Mappings example

Más contenido relacionado

La actualidad más candente

The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural StyleRobert Wilson
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended VersionJeremy Brown
 
Impact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilityImpact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilitySanchit Gera
 
Net framework key components - By Senthil Chinnakonda
Net framework key components - By Senthil ChinnakondaNet framework key components - By Senthil Chinnakonda
Net framework key components - By Senthil Chinnakondatalenttransform
 
Representational state transfer (rest) architectural style1.1
Representational state transfer (rest) architectural style1.1Representational state transfer (rest) architectural style1.1
Representational state transfer (rest) architectural style1.1Vinod Wilson
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Martin Necasky
 
Soa 10 soa technology soap
Soa 10 soa technology soapSoa 10 soa technology soap
Soa 10 soa technology soapVaibhav Khanna
 
Web services for developer
Web services for developerWeb services for developer
Web services for developerRafiq Ahmed
 
Soa 9 soa technologies wsdl
Soa 9 soa technologies wsdlSoa 9 soa technologies wsdl
Soa 9 soa technologies wsdlVaibhav Khanna
 
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...ecosio GmbH
 

La actualidad más candente (20)

Restful web services
Restful web servicesRestful web services
Restful web services
 
The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural Style
 
Web Services
Web ServicesWeb Services
Web Services
 
Xml schema
Xml schemaXml schema
Xml schema
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended Version
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
 
Introduction to HTTP
Introduction to HTTPIntroduction to HTTP
Introduction to HTTP
 
Impact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilityImpact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and Scalability
 
Web technologies: HTTP
Web technologies: HTTPWeb technologies: HTTP
Web technologies: HTTP
 
Net framework key components - By Senthil Chinnakonda
Net framework key components - By Senthil ChinnakondaNet framework key components - By Senthil Chinnakonda
Net framework key components - By Senthil Chinnakonda
 
Representational state transfer (rest) architectural style1.1
Representational state transfer (rest) architectural style1.1Representational state transfer (rest) architectural style1.1
Representational state transfer (rest) architectural style1.1
 
80068
8006880068
80068
 
Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)Web Services - Architecture and SOAP (part 1)
Web Services - Architecture and SOAP (part 1)
 
Soa 10 soa technology soap
Soa 10 soa technology soapSoa 10 soa technology soap
Soa 10 soa technology soap
 
Web service architecture
Web service architectureWeb service architecture
Web service architecture
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
Web services for developer
Web services for developerWeb services for developer
Web services for developer
 
Soa 9 soa technologies wsdl
Soa 9 soa technologies wsdlSoa 9 soa technologies wsdl
Soa 9 soa technologies wsdl
 
SOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIESSOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIES
 
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
 

Similar a RESTful web services using java and spring

Similar a RESTful web services using java and spring (20)

Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Starting With Php
Starting With PhpStarting With Php
Starting With Php
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
Web
WebWeb
Web
 
Learn REST API at ASIT
Learn REST API at ASITLearn REST API at ASIT
Learn REST API at ASIT
 
HTTP
HTTPHTTP
HTTP
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systems
 
HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocol
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
www and http services
www and http serviceswww and http services
www and http services
 
HTTP
HTTPHTTP
HTTP
 
HTTP1.1/2 overview
HTTP1.1/2 overviewHTTP1.1/2 overview
HTTP1.1/2 overview
 
Ch-1_.ppt
Ch-1_.pptCh-1_.ppt
Ch-1_.ppt
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 

Último

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 

Último (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 

RESTful web services using java and spring

  • 1.
  • 2. By Muhammad Junaid REST ● REST stands for Representational State Transfer -Design pattern for developing web services. ● Resource based ● Rest Style: ● Client-server ● Uniform interface ● Stateless ● Cached ● Layered system ● HATEOAS - (Hypermedia As The Engine Of Application State)
  • 3. By Muhammad Junaid REST - not a Standard ● But it uses several standards: o HTTP o URL o XML/HTML/GIF/JPEG/etc (Resource Representations) o text/xml, text/html, image/gif, image/jpeg, etc (Resource Types, MIME Types) Browser Web ServerGET /index.html HTTP/1.1 Host: www.pitt.edu HTTP/1.1 200 OK Content-Type: text/html
  • 4. By Muhammad Junaid Rest API Concepts  Services exposed to internet for programmatic access  Users can be either producers or consumers or both  Eg : api.twitter.com  Data can be returned in the form of XML /JSON / etc  Helps developers to parse data.  Messages can be exchanged in any kind of HTTP method
  • 5. By Muhammad Junaid 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.)
  • 6. By Muhammad Junaid Sample Client Requests: GET /view?id=1 HTTP/1.1 Request Headers User-Agent: Chrome Accept: application/json Requested Resource (path and query string) (no request body) POST /save HTTP/1.1 Requested Resource (typically no query string) User-Agent: IE Content-Type: application/x-www-form-urlencoded Request Headers name=x&id=2 Request Body (e.g. form parameters)
  • 7. By Muhammad Junaid HTTP Response • The HTTP response is sent from the server. – Gives the status of the processed request. – Supplies response headers (name-value pairs) that provide additional information about the response. – Supplies an optional response body that identifies additional data to be downloaded to the client (html, xml, binary data, etc.) – -HTTP Status codes(1xx, 2xx, 3xx, 4xx, 5xx)
  • 8. By Muhammad Junaid Sample Server Responses: HTTP/1.1 200 OK Content-Type: text/html Content-Length: 1337 [CRLF] <html> <!-- Some HTML Content. --> </html> HTTP/1.1 500 Internal Server Error HTTP/1.1 201 Created Location: /view/7 [CRLF] Some message goes here. Response Status Response Headers Response Body (content) Response Status Response Header Response Body Response Status
  • 9. By Muhammad Junaid 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
  • 10. By Muhammad Junaid Action/Verb  /orders  GET - list all orders  POST - submit a new order  /orders/{order-id}  GET - get an order representation  PUT - update an order  DELETE - cancel an order  /orders/average-sale  GET - calculate average sale  /customers  GET - list all customers  POST - create a new customer  /customers/{cust-id}  GET - get a customer representation  DELETE- remove a customer  /customers/{cust-id}/orders  GET - get the orders of a customer
  • 11. By Muhammad Junaid A typical HTTP REST URL: http://my.store.com/fruits/list?category=fruit&limit=20 • 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
  • 12. By Muhammad Junaid Representations (MediaType)  XML <COURSE> <ID>CS2650</ID> <NAME>Distributed Multimedia Software</NAME> </COURSE>  JSON { “course”: { “id”: “CS2650” “name”: “Distributed Multimedia Software” } }
  • 13. By Muhammad Junaid 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
  • 14. By Muhammad Junaid Examples of Rest URIs Insert new customer in a system POST http://www.example.com/customers/12345 Read a customer with customer ID GET http://www.example.com/customers/33245 Read all orders with customer ID GET http://www.example.com/customers/33245/orde rs
  • 15. By Muhammad Junaid 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)
  • 16. By Muhammad Junaid Jersey  One of the libraries that implements JAX-RS , from Oracle.  Other libraries in the market -* Apache CXF , an open source Web service framework . * RESTeasy , JBoss 's implementation . * Restlet . * Apache Wink , Apache Software Foundation Incubator . * WebSphere Application Server from IBM.  Choice of library doesn’t matter .
  • 18. By Muhammad Junaid SOAP vs. REST: Overview Both 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.
  • 19. By Muhammad Junaid 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
  • 20. By Muhammad Junaid Restful Webservices ● A RESTful Web service follows four basic design principles: o Uses HTTP methods o Be stateless as far as possible o Expose directory/folder structure-like URI o Transfer XML, JSON, or both
  • 21. By Muhammad Junaid Web.xml configuration <servlet> <servlet-name>AccountService</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AccountService</servlet-name> <url-pattern>services/*</url-pattern> </servlet-mapping>
  • 22. By Muhammad Junaid @Path  Sets the path to base URL + /your_path. The base URL is based on your application name, the servlet and the URL pattern from the web.xml configuration file.
  • 23. By Muhammad Junaid @GET, @PUT, @POST, @DELETE, ...
  • 24. By Muhammad Junaid @Produces  @Produces defines which MIME type is delivered by a method annotated with @GET. In  the example text ("text/plain") is produced. Other examples would be "application/xml"  or "application/json"
  • 25. By Muhammad Junaid URI Mappings example

Notas del editor

  1. Agenda: Overview of REST architecture, Basics of HTTP, Implementation with Spring and examples.
  2. CSS, Visibility, Scalability
  3. Patch method – partial update
  4. 1
  5. Traversing the response directory structure by asking specific information based on ID.
  6. Why use JAX-RS. Comparisons with spring mvc implementation.