SlideShare a Scribd company logo
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

More Related Content

What's hot

Restful web services
Restful web servicesRestful web services
Restful web services
Surinder Mehra
 
The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural Style
Robert Wilson
 
Xml schema
Xml schemaXml schema
Xml schema
Dr.Saranya K.G
 
A Conversation About REST - Extended Version
A Conversation About REST - Extended VersionA Conversation About REST - Extended Version
A Conversation About REST - Extended VersionJeremy Brown
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
princeirfancivil
 
Introduction to HTTP
Introduction to HTTPIntroduction to HTTP
Introduction to HTTP
Seble Nigussie
 
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
Sanchit 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 Chinnakonda
talenttransform
 
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
Vinod Wilson
 
80068
8006880068
80068
DEEPIKA T
 
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 soap
Vaibhav Khanna
 
Web service architecture
Web service architectureWeb service architecture
Web service architecture
Muhammad Shahroz Anwar
 
Web services for developer
Web services for developerWeb services for developer
Web services for developer
Rafiq Ahmed
 
Soa 9 soa technologies wsdl
Soa 9 soa technologies wsdlSoa 9 soa technologies wsdl
Soa 9 soa technologies wsdl
Vaibhav Khanna
 
SOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIESSOAP WEB TECHNOLOGIES
SOAP WEB TECHNOLOGIES
tamilmozhiyaltamilmo
 
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
 

What's hot (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 to RESTful web services using java and spring

Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
Vinay Gopinath
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
hussulinux
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
Hoan Vu Tran
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
KGSCSEPSGCT
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
Sudheer Satyanarayana
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
Suresh Madhra
 
Learn REST API at ASIT
Learn REST API at ASITLearn REST API at ASIT
Learn REST API at ASIT
ASIT
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systemsReza Gh
 
HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.HTTP 완벽가이드 1장.
HTTP 완벽가이드 1장.
HyeonSeok Choi
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocolwanangwa234
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
Sahil Agarwal
 
Overview of java web services
Overview of java web servicesOverview of java web services
www and http services
www and http serviceswww and http services
www and http services
Jenica Salmorin
 
HTTP1.1/2 overview
HTTP1.1/2 overviewHTTP1.1/2 overview
HTTP1.1/2 overview
Andrew Muntian
 
Ch-1_.ppt
Ch-1_.pptCh-1_.ppt
Ch-1_.ppt
berihunmolla2
 
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.jsCarol McDonald
 

Similar to 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
 

Recently uploaded

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 

Recently uploaded (20)

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 

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

Editor's Notes

  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.