SlideShare une entreprise Scribd logo
1  sur  37
hSenid Lanka: Rest & RESTful Web Services
By Kasun Dinesh Madusanke
REST & RESTful WEB
SERVICES
hSenid Lanka: REST
2
Topics
o Introduction
o Resources
o Requests & Responses
o Addressing
o Methods
o Statelessness & Caching
o HATEOAS
3
Topics Cont.
o JAX-RS
o Some JAX-RS Annotations
o JAX-RS Implementations
o Demo
o Status Codes in Brief
o Benefits of REST
o REST vs SOAP
hSenid Lanka: REST
4
Introduction
▸Representational State Transfer.
▸Introduced by Roy Fielding in 2000.
▸Architectural style (technically not a standard).
▸Uses existing standards, e.g., HTTP.
▸REST is an architecture all about the Client-Server
communication.
▸REST is about how to manipulate resources.
hSenid Lanka: REST
5
Some more about REST
▸Client requests a specific resource from the server.
▸The server responds to that request by delivering the
requested resource.
▸Server does not have any information about any client.
▸So, there is no difference between the two requests of
the same client.
hSenid Lanka: REST
6
Resources
▸REST Server provides access to resources and
REST client accesses and presents the resources.
▸Here each resource is identified by URIs/ global
IDs.
▸REST uses various representations to represent a
resource like text, JSON and XML.
hSenid Lanka: REST
7
URI-Example
▸GET – get the book whose id is provided
▸POST – update the book whose id is provided
▸DELETE – delete the book whose id is provided
http://localhost:9999/restapi/books/{id}
hSenid Lanka: REST
8
Resource Representation
▸ JSON
▸ XML
hSenid Lanka: REST
9
Requests & Responses
▸RESTful web services uses HTTP protocol as the
medium to help the communication between
client and server.
▸Client sends HTTP Request.
▸Server responds it by sending a HTTP Response.
▸This is called as messaging as well.
hSenid Lanka: REST
10
HTTP Request
hSenid Lanka: REST
11
▸Verb- Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
▸URI- Uniform Resource Identifier (URI) to identify the resource on
server.
▸HTTP Version- Indicate HTTP version.
▸Request Header- Contains metadata for the HTTP Request
message as key-value pairs.
▸Request Body- Message content or Resource representation.
HTTP Request Cont.
hSenid Lanka: REST
12
HTTP Response
hSenid Lanka: REST
13
▸Status/Response Code- Indicate Server status for the requested
resource.
▸HTTP Version- Indicate HTTP version, for example HTTP v1.1 .
▸Response Header- Contains metadata for the HTTP Response
message as key-value pairs. For example, content length, content
type, response date, server type etc.
▸Response Body- Response message content or Resource
representation.
HTTP Response Cont.
hSenid Lanka: REST
14
Addressing
▸Addressing refers to locating a resource or
resources on the server.
▸It is analogous to locate a postal address of a
person.
▸Each resource in REST architecture is identified
by its URI.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
hSenid Lanka: REST
15
Methods
Method URI Description
GET
(Read)
http://localhost:8080/UserManagement/
rest/UserService/users
http://localhost:8080/UserManagement/
rest/UserService/users/1
Get list of users.
Get user of id=1.
POST
(Create/
Update)
http://localhost:8080/UserManagement/
rest/UserService/users/2
Update user
where
user id=2.
PUT
(Update)
http://localhost:8080/UserManagement/
rest/UserService/users/2
Insert user with
id=2.
hSenid Lanka: REST
16
Methods Cont.
Method URI Description
Delete
(Delete)
http://localhost:8080/UserManagem
ent/rest/UserService/users/1
Delete user
where user id=1.
Options
http://localhost:8080/UserManagem
ent/rest/UserService/users
List supported
web service
operations.
Head
http://localhost:8080/UserManagem
ent/rest/UserService/users
Returns HTTP
header only.
hSenid Lanka: REST
17
Statelessness
▸Each request is independent from other requests.
▸No client session data or any context stored on
the server.
▸If there are needs for session-specific data, it
should be held and maintained by the client and
transferred to the server with each request as
needed.
hSenid Lanka: REST
18
Statelessness Cont.
 Cons
▸The client must load the required information
to every request. And this increases the network
traffic.
▸Server might be loaded with heavy work of
«validation» of requests.
hSenid Lanka: REST
19
Caching
▸HTTP responses must be cacheable by the
clients.
▸Important for performance.
▸If a new request for the resources comes
within a while, then the cached response will
be returned.
hSenid Lanka: REST
20
Caching Cont.
hSenid Lanka: REST
21
hSenid Lanka: REST
HATEOAS
Hypermedia As The Engine Of Application State
▸Use links to allow clients to discover locations and
operations.
▸Link relations are used to express options.
▸Clients do not need to know URLs.
▸This controls the state.
▸e.g: Where the user is, Instructions on user’s next
steps.
22
hSenid Lanka: REST
HATEOAS Cont.
▸Links contain
▹The target (href, mandatory).
▹A short relationship indication (rel, mandatory).
• (e. g. “details”, “payment”, “cancel”).
▹The content type needed for the request (type, optional).
▹The HTTP method (method, optional).
23
hSenid Lanka: REST
HATEOAS Cont.
Sample HATEOAS-based response
24
JAX-RS
▸JAX-RS stands for JAVA API for RESTful Web
Services.
▸JAX-RS is a JAVA based programming language
API and specification to provide support for
created RESTful Web services.
▸JAX-RS makes heavy use of annotations to
simplify development of JAVA based web services.
hSenid Lanka: REST
25
Some JAX-RS Annotations
Annotation Description
@Path Relative path of the resource class/method.
@GET Used to fetch resource.
@POST Used to create/update resource.
@DELETE Used to delete resource.
@HEAD Used to get status of method availability.
@PUT Used to create resource.
hSenid Lanka: REST
26
Some JAX-RS Annotations Cont.
Annotation Description
@PathParam
Binds the parameter passed to method to a
value in path.
@QueryParam
Binds the parameter passed to method to a
query parameter in path.
@FormParam
Binds the parameter passed to method to a
form value.
@CookieParam
Binds the parameter passed to method to a
Cookie.
@HeaderParam
Binds the parameter passed to method to a
HTTP header.
hSenid Lanka: REST
27
JAX-RS Implementations
▸Apache CXF, an open source Web service
framework.
▸Jersey, the reference implementation from Sun
(now Oracle).
▸RESTeasy, JBoss's implementation.
▸Restlet.
▸WebSphere Application Server from IBM.
hSenid Lanka: REST
28
DEMO
hSenid Lanka: REST
29
Status Codes in Brief
Code type Description
1XX Informational
2XX Success
3XX Redirection
4XX Client Error
5XX Server Error
hSenid Lanka: REST
30
Status Codes in Brief
▸200 OK
The request has succeeded.
▸201 Created
The request has succeeded and a new resource has been
created as a result of it.
▸301 Moved Permanently
URI of requested resource has been changed.
▸307 Temporary Redirect
Directing client to get requested resource to another URI.
hSenid Lanka: REST
31
▸308 Permanent Redirect
Resource is now permanently located at another URI.
▸400 Bad Request
Server could not understand the request due to
invalid syntax.
▸403 Forbidden
Client does not have access rights to the content so
server is rejecting to give proper response.
Status Codes in Brief
hSenid Lanka: REST
32
▸404 Not Found
Server can not find requested resource.
▸500 Internal Server Error
The server has encountered a situation it doesn't know how
to handle.
▸503 Service Unavailable
The server is not ready to handle the request.
▸505 HTTP Version Not Supported
The HTTP version used in the request is not supported by the
server.
Status Codes in Brief
hSenid Lanka: REST
33
Benefits of REST
▸It helps you organize even a very complex application
into simple resources.
▸Security: Use HTTPS.
▸Performance: REST is less CPU expensive.
▸Complexity: REST demands much less in terms of
setup, it's just GET/POST after all. SOAP requires much
more administration to maintain.
hSenid Lanka: REST
34
hSenid Lanka: REST
REST vs SOAP
REST SOAP
A style. A standard.
Proper REST: Transport must be
HTTP/HTTPS.
Normally transport is HTTP/HTTPS
but can be something else.
Response data is normally
transmitted as XML, can be
something else.
Response data is transmitted as
XML.
Request is transmitted as URI. Request is transmitted as XML.
35
hSenid Lanka: REST
REST vs SOAP Cont.
REST SOAP
Easy to be called from JavaScript.
JavaScript can call SOAP but it is
hard, and not very elegant.
If JSON is returned it is very
powerful.
JavaScript parsing XML is slow and
the methods differ from browser to
browser.
Simply calls services via URL path.
Invokes services by calling RPC
method.
result is readable with is just plain
XML or JSON.
Doesn't return human readable
result.
36
hSenid Lanka: REST
Summary
▸Resources, Requests & Responses, Addressing,
Methods (GET, POST, PUT,..), Statelessness &
Caching.
▸JAX-RS, Annotations (@FormParam, @pathParam,
@Path, @GET,…), & Implementations (Jersey).
37hSenid Lanka: Rest & RESTful Web Services
By Kasun Dinesh Madusanke
THANK
YOU!
Download code from GitHub

Contenu connexe

Tendances

Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web ServicesAngelin R
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedDhananjay Nene
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST Ram Awadh Prasad, PMP
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - APIChetan Gadodia
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsStormpath
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 
Asp Net Advance Topics
Asp Net Advance TopicsAsp Net Advance Topics
Asp Net Advance TopicsAli Taki
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST APIAmilaSilva13
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful ArchitectureKabir Baidya
 
Authentication
AuthenticationAuthentication
Authenticationsoon
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocolAviran Mordo
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 

Tendances (20)

An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
What is an API?
What is an API?What is an API?
What is an API?
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) Explained
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Soap and Rest
Soap and RestSoap and Rest
Soap and Rest
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Asp Net Advance Topics
Asp Net Advance TopicsAsp Net Advance Topics
Asp Net Advance Topics
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful Architecture
 
Authentication
AuthenticationAuthentication
Authentication
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocol
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
REST API
REST APIREST API
REST API
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 

Similaire à REST and RESTful Web Services

Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring FrameworkArcadian Learning
 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with javaVinay Gopinath
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASGuy K. Kloss
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling ResolutionDEEPAK KHETAWAT
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaVladimir Tsukur
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandMatthew Turland
 
Rest and beyond
Rest and beyondRest and beyond
Rest and beyondMing Yuan
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.pptKGSCSEPSGCT
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful Jon Chen
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 

Similaire à REST and RESTful Web Services (20)

ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
 
A Look at OData
A Look at ODataA Look at OData
A Look at OData
 
Rest and beyond
Rest and beyondRest and beyond
Rest and beyond
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
 
C# REST API
C# REST APIC# REST API
C# REST API
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful
 
Rest introduction
Rest introductionRest introduction
Rest introduction
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 

Dernier

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Dernier (20)

VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

REST and RESTful Web Services

  • 1. hSenid Lanka: Rest & RESTful Web Services By Kasun Dinesh Madusanke REST & RESTful WEB SERVICES
  • 2. hSenid Lanka: REST 2 Topics o Introduction o Resources o Requests & Responses o Addressing o Methods o Statelessness & Caching o HATEOAS
  • 3. 3 Topics Cont. o JAX-RS o Some JAX-RS Annotations o JAX-RS Implementations o Demo o Status Codes in Brief o Benefits of REST o REST vs SOAP hSenid Lanka: REST
  • 4. 4 Introduction ▸Representational State Transfer. ▸Introduced by Roy Fielding in 2000. ▸Architectural style (technically not a standard). ▸Uses existing standards, e.g., HTTP. ▸REST is an architecture all about the Client-Server communication. ▸REST is about how to manipulate resources. hSenid Lanka: REST
  • 5. 5 Some more about REST ▸Client requests a specific resource from the server. ▸The server responds to that request by delivering the requested resource. ▸Server does not have any information about any client. ▸So, there is no difference between the two requests of the same client. hSenid Lanka: REST
  • 6. 6 Resources ▸REST Server provides access to resources and REST client accesses and presents the resources. ▸Here each resource is identified by URIs/ global IDs. ▸REST uses various representations to represent a resource like text, JSON and XML. hSenid Lanka: REST
  • 7. 7 URI-Example ▸GET – get the book whose id is provided ▸POST – update the book whose id is provided ▸DELETE – delete the book whose id is provided http://localhost:9999/restapi/books/{id} hSenid Lanka: REST
  • 8. 8 Resource Representation ▸ JSON ▸ XML hSenid Lanka: REST
  • 9. 9 Requests & Responses ▸RESTful web services uses HTTP protocol as the medium to help the communication between client and server. ▸Client sends HTTP Request. ▸Server responds it by sending a HTTP Response. ▸This is called as messaging as well. hSenid Lanka: REST
  • 11. 11 ▸Verb- Indicate HTTP methods such as GET, POST, DELETE, PUT etc. ▸URI- Uniform Resource Identifier (URI) to identify the resource on server. ▸HTTP Version- Indicate HTTP version. ▸Request Header- Contains metadata for the HTTP Request message as key-value pairs. ▸Request Body- Message content or Resource representation. HTTP Request Cont. hSenid Lanka: REST
  • 13. 13 ▸Status/Response Code- Indicate Server status for the requested resource. ▸HTTP Version- Indicate HTTP version, for example HTTP v1.1 . ▸Response Header- Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc. ▸Response Body- Response message content or Resource representation. HTTP Response Cont. hSenid Lanka: REST
  • 14. 14 Addressing ▸Addressing refers to locating a resource or resources on the server. ▸It is analogous to locate a postal address of a person. ▸Each resource in REST architecture is identified by its URI. <protocol>://<service-name>/<ResourceType>/<ResourceID> hSenid Lanka: REST
  • 15. 15 Methods Method URI Description GET (Read) http://localhost:8080/UserManagement/ rest/UserService/users http://localhost:8080/UserManagement/ rest/UserService/users/1 Get list of users. Get user of id=1. POST (Create/ Update) http://localhost:8080/UserManagement/ rest/UserService/users/2 Update user where user id=2. PUT (Update) http://localhost:8080/UserManagement/ rest/UserService/users/2 Insert user with id=2. hSenid Lanka: REST
  • 16. 16 Methods Cont. Method URI Description Delete (Delete) http://localhost:8080/UserManagem ent/rest/UserService/users/1 Delete user where user id=1. Options http://localhost:8080/UserManagem ent/rest/UserService/users List supported web service operations. Head http://localhost:8080/UserManagem ent/rest/UserService/users Returns HTTP header only. hSenid Lanka: REST
  • 17. 17 Statelessness ▸Each request is independent from other requests. ▸No client session data or any context stored on the server. ▸If there are needs for session-specific data, it should be held and maintained by the client and transferred to the server with each request as needed. hSenid Lanka: REST
  • 18. 18 Statelessness Cont.  Cons ▸The client must load the required information to every request. And this increases the network traffic. ▸Server might be loaded with heavy work of «validation» of requests. hSenid Lanka: REST
  • 19. 19 Caching ▸HTTP responses must be cacheable by the clients. ▸Important for performance. ▸If a new request for the resources comes within a while, then the cached response will be returned. hSenid Lanka: REST
  • 21. 21 hSenid Lanka: REST HATEOAS Hypermedia As The Engine Of Application State ▸Use links to allow clients to discover locations and operations. ▸Link relations are used to express options. ▸Clients do not need to know URLs. ▸This controls the state. ▸e.g: Where the user is, Instructions on user’s next steps.
  • 22. 22 hSenid Lanka: REST HATEOAS Cont. ▸Links contain ▹The target (href, mandatory). ▹A short relationship indication (rel, mandatory). • (e. g. “details”, “payment”, “cancel”). ▹The content type needed for the request (type, optional). ▹The HTTP method (method, optional).
  • 23. 23 hSenid Lanka: REST HATEOAS Cont. Sample HATEOAS-based response
  • 24. 24 JAX-RS ▸JAX-RS stands for JAVA API for RESTful Web Services. ▸JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Web services. ▸JAX-RS makes heavy use of annotations to simplify development of JAVA based web services. hSenid Lanka: REST
  • 25. 25 Some JAX-RS Annotations Annotation Description @Path Relative path of the resource class/method. @GET Used to fetch resource. @POST Used to create/update resource. @DELETE Used to delete resource. @HEAD Used to get status of method availability. @PUT Used to create resource. hSenid Lanka: REST
  • 26. 26 Some JAX-RS Annotations Cont. Annotation Description @PathParam Binds the parameter passed to method to a value in path. @QueryParam Binds the parameter passed to method to a query parameter in path. @FormParam Binds the parameter passed to method to a form value. @CookieParam Binds the parameter passed to method to a Cookie. @HeaderParam Binds the parameter passed to method to a HTTP header. hSenid Lanka: REST
  • 27. 27 JAX-RS Implementations ▸Apache CXF, an open source Web service framework. ▸Jersey, the reference implementation from Sun (now Oracle). ▸RESTeasy, JBoss's implementation. ▸Restlet. ▸WebSphere Application Server from IBM. hSenid Lanka: REST
  • 29. 29 Status Codes in Brief Code type Description 1XX Informational 2XX Success 3XX Redirection 4XX Client Error 5XX Server Error hSenid Lanka: REST
  • 30. 30 Status Codes in Brief ▸200 OK The request has succeeded. ▸201 Created The request has succeeded and a new resource has been created as a result of it. ▸301 Moved Permanently URI of requested resource has been changed. ▸307 Temporary Redirect Directing client to get requested resource to another URI. hSenid Lanka: REST
  • 31. 31 ▸308 Permanent Redirect Resource is now permanently located at another URI. ▸400 Bad Request Server could not understand the request due to invalid syntax. ▸403 Forbidden Client does not have access rights to the content so server is rejecting to give proper response. Status Codes in Brief hSenid Lanka: REST
  • 32. 32 ▸404 Not Found Server can not find requested resource. ▸500 Internal Server Error The server has encountered a situation it doesn't know how to handle. ▸503 Service Unavailable The server is not ready to handle the request. ▸505 HTTP Version Not Supported The HTTP version used in the request is not supported by the server. Status Codes in Brief hSenid Lanka: REST
  • 33. 33 Benefits of REST ▸It helps you organize even a very complex application into simple resources. ▸Security: Use HTTPS. ▸Performance: REST is less CPU expensive. ▸Complexity: REST demands much less in terms of setup, it's just GET/POST after all. SOAP requires much more administration to maintain. hSenid Lanka: REST
  • 34. 34 hSenid Lanka: REST REST vs SOAP REST SOAP A style. A standard. Proper REST: Transport must be HTTP/HTTPS. Normally transport is HTTP/HTTPS but can be something else. Response data is normally transmitted as XML, can be something else. Response data is transmitted as XML. Request is transmitted as URI. Request is transmitted as XML.
  • 35. 35 hSenid Lanka: REST REST vs SOAP Cont. REST SOAP Easy to be called from JavaScript. JavaScript can call SOAP but it is hard, and not very elegant. If JSON is returned it is very powerful. JavaScript parsing XML is slow and the methods differ from browser to browser. Simply calls services via URL path. Invokes services by calling RPC method. result is readable with is just plain XML or JSON. Doesn't return human readable result.
  • 36. 36 hSenid Lanka: REST Summary ▸Resources, Requests & Responses, Addressing, Methods (GET, POST, PUT,..), Statelessness & Caching. ▸JAX-RS, Annotations (@FormParam, @pathParam, @Path, @GET,…), & Implementations (Jersey).
  • 37. 37hSenid Lanka: Rest & RESTful Web Services By Kasun Dinesh Madusanke THANK YOU! Download code from GitHub