This presentation covers basics of RESTful webservices. I have prepared it by reading different online tutorials. One of them is java brains video tutorial. Hope this helps some one.
If any one needs examples mentioned in the slides, please contact me.
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Restful web services
1. S U R I N D E R K U M A R M E H R A
7 T H S E P T , 2 0 1 5
For "REST“, keep watching. For others,
Open Rest.
RESTFul Web Services
2. Outline
Introduction
REST and HTTP
Resource Types
Base URL
HTTP Methods
Method Idempotence
HATEOAS
Richardson Maturity
Model
Path and Query Params
Pagination and Filtering
Sub Resources
Exceptions
Content Negotiation
3. Introduction
REpresentational State Transfer (REST)
An architectural Style
Coordinated set of constraints to
distributed hypermedia system components design
REST+Web Services = RESTFul Web Services
Web sites use HTML with format and styling
Meant for human consumption
REST use XML/JSON without styling- bare bone
data
Meant of Developers to use and style accordingly
Has specific URL for each operation
Just like static web page web sites
5. Characteristics of Web Services
Communication always happens over Web/HTTP
Protocols:
SOAP Web services: SOAP format
REST: none… Can be XML/JSON/TEXT as long as client
server understand each other
Data Exchange:
SOAP: Always POST
REST: Different methods for different purpose
Service definition:
SOAP: WSDL
REST: None
6. Why No Rules in REST
SOAP WS follow SOAP Web service Specification
If SOAP WS does no follow even one rule , its not SOAP WS
Committee maintains the rules
REST is a concept introduced by Roy Fielding
There is no committee to make rules
7. Why REST
• Used when lot of tiny data is needed
• Easy to build- No toolkit required
• Light weight- NO xml markup
• Independence- no strict rules like SOAP
• For bulk operations like detailed purchase order may not be
possible with REST
8. Little bit about HTTP
HTTP: Hyper Text Transfer Protocol
HTTP is a way to transfer/exchange hypertext
Hypertext is a structured text which contains logical links to
other text.
Logical links are called hyperlinks
A common way to write hyper text is HTML
HTML: Hyper Text Markup Language
10. HTTP & REST
Address Resource Locations:
Web sites use action based URI’s
weatherapp.com/weatherLookup.do?zipcode=1234
REST uses resource based URI’s
weatherapp.com/zipcode/1234
weatherapp.com/cities/Bengaluru
Methods: GET, PUT , POST, DELETE
Metadata:
Status Codes: Defines status of response received
Message Headers: type of data sent/received
Roy Fielding was one of the principal authors of HTTP Specification
13. Method Idempotence
Idempotence :
Resource state on server is same before and after the
operation with same data
PUT and DELETE are idempotent
GET is Safe and therefore Idempotent
POST is not idempotent
• Why ?
14. HATEOAS
Hypermedia
As
The
Engine
Of
Application
State
In short provides dynamic current Application state
15. Richardson Maturity Model
Level 0: Swamp Of POX(Plain Old XML)
Uses one entry point and one method-SOAP
Level 1: Resource URI’s
Individual URI’s for each resource and one method
Level 2: HTTP Methods
Uses the right HTTP method and status codes
Level 3: HATEOAS
Response have links that client can use further
17. Pagination & Filtering
@QueryParam: Apply to request as a whole
@MatrixParam: Apply to path element
@BeanParam: Useful when lot of params are
needed.
Collection Resource supports query params:
Offset
Limit
…/messages?offset=50&limit=25
19. Status Codes and Location Headers
Return proper Status Code in Response
201 instead of 200 when POST is successful
Send Location Headers in Response