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

introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST APIAmilaSilva13
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 SlidesSuraj Gupta
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developersPatrick Savalle
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - APIChetan Gadodia
 
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
 
Web servers – features, installation and configuration
Web servers – features, installation and configurationWeb servers – features, installation and configuration
Web servers – features, installation and configurationwebhostingguy
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
The Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReSTThe Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReSTBruno Kessler Foundation
 
Chapter 1 semantic web
Chapter 1 semantic webChapter 1 semantic web
Chapter 1 semantic webR A Akerkar
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search medcl
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and responseSahil Agarwal
 
Introduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web ServicesIntroduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web Servicesecosio GmbH
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 

Tendances (20)

introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
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)
 
Web servers – features, installation and configuration
Web servers – features, installation and configurationWeb servers – features, installation and configuration
Web servers – features, installation and configuration
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
The Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReSTThe Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReST
 
C# REST API
C# REST APIC# REST API
C# REST API
 
Rest API
Rest APIRest API
Rest API
 
Chapter 1 semantic web
Chapter 1 semantic webChapter 1 semantic web
Chapter 1 semantic web
 
quick intro to elastic search
quick intro to elastic search quick intro to elastic search
quick intro to elastic search
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
Introduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web ServicesIntroduction to SOAP/WSDL Web Services and RESTful Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web Services
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 

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
 
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
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 

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
 
Restful web services
Restful web servicesRestful web services
Restful web services
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
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
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Rest surekha
Rest surekhaRest surekha
Rest surekha
 

Dernier

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Dernier (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

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