SlideShare a Scribd company logo
Introduction to RESTful
Web Services
09/2012
Wei Li
Agenda
• RESTful in General
• URI Design
• Java Implementation
• Others
• Test
• Demonstration
RESTful in General
In a Nutshell
• RESTful is about resources
• RESTful is about how to represent the
resource in different ways
• RESTful is about how to manipulate the
resource
Define REST
• REST stands for Representational State
Transfer
• An architecture style for designing networked
applications
Define REST
• REST offers a simple, interoperable, and
flexible way of writing web services that can
be very different than the RPC mechanisms
like CORBA and WS-*
RESTful Is Not
• A protocol
• A standard
• A replacement for SOAP
RESTful Architectural Principles
• Addressable resources
• A uniform, constrained interface
• Representation oriented
• Stateless communicate
• Hypermedia As The Engine Of Application
State (HATEOAS)
Resources
• The key abstraction of information and data in
REST
• Each resource must be addressable via a URI
(Uniform Resource Identifier)
• Everything can be a resource
Addressability
• Every object and resource in the system
should be reachable through a unique
identifier
• Managed through the use of URIs
Uniform and Constrained Interface
• Don’t have an “action” parameter in URI
• Use only the methods of HTTP for the web
services
• HTTP has a small fixed set of operational
methods. Each method has a specific purpose
and meaning
Representation Oriented
• The user interacts with services using
representations of that service
• A resource referenced by one URI can have
different formats.
– HTML (for browsers)
– XML (for application)
– JSON (for JavaScript)
– Excel spreadsheet
– Image
Stateless Communication
• No client session data 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
• A service layer that does not have to maintain
client sessions is much easier to scale
RESTful and HTTP
• REST isn't protocol specific
• However when talking about REST, people
usually mean REST over HTTP
• Benefits of using HTTP for RESTful services:
 Familiarity
 Interoperability
 Interoperability
REST Triangle
Source: http://en.wikipedia.org/wiki/File:Resttriangle.svg
HTTP Methods
• GET
• PUT
• DELETE
• POST
• HEAD
• OPTIONS
CRUD Operation Mapped
to HTTP Methods in RESTful
OPERATION HTTP METHOD
Create POST
Read GET
Update PUT
Delete DELETE
HTTP Response Code
• 200 OK
• 201 Created
• 202 Accepted
• 204 Success
• 301 Moved Permanently
• 302 Found
• 303 See Other
• 304 Not Modified
• 500 Internal Error
• 503 Service Unavailable
HTTP Response Code
• 401 Unauthorized
• 403 Forbidden
• 404 Not Found
• 405 Method Not Allowed
• 409 Conflict
• 411 Length Required
• 413 Entity Too Long
• 415 Unsupported Media Type
Create a Resource
Source: Rest in Practice
Read a Resource
Source: Rest in Practice
Update a Resource
Source: Rest in Practice
Delete a Resource
Source: Rest in Practice
URI Design
URI
• Human meaningful
• Hierarchical
• Nouns
• No verbs
URI Examples
• http://localhost:9999/restapi/books
– GET – get all books
– POST – add a new book
• http://localhost:9999/restapi/books/{id}
– GET – get book whose id is provided
– PUT – update the book whose id is provided
– DELETE – delete the book whose is provided
URI Examples
• Twitter REST API v1.1 example:
– https://dev.twitter.com/docs/api/1.1
Content Negotiation
Content Negotiation and URI
• http://localhost:9999/restapi/books/{id}.xml
• http://localhost:9999/restapi/books/{id}.json
• http://localhost:9999/restapi/books/{id}.pdf
Content Negotiation and URI
• https://cwiki.apache.org/WINK/jax-rs-
content-negotiation.html
Java Implementation
JSR-311
• POJO based
• HTTP centric
• Format independence
• Container independence
• Inclusion in Java EE
JSR-311 Annotations
JSR 311 Annotations
Available Java Frameworks
• Jersey
• CXF
• Wink
• RESTEasy
Others
WADL
• The Web Application Description
Language
• A machine-readable XML description of
HTTP-based web applications (typically
RESTful web services).
WADL
• Example (using Jersey implementation)
http://localhost:9999/restapi/application.wadl
Versioning
• Put the version in URI
http://localhost:9999/restapi/v2.0/books
Versioning
• put the version in the Accept Header of
the request
http://stackoverflow.com/questions/389169/
best-practices-for-api-
versioning/6750376#6750376
Security
• HTTPS (encrypt channel)
• Web ACL
• Others (more advanced)
Error Handling
• Use standard error message format as
response
• Use Non-200 response codes
HTTP/1.1 400 Bad Request
Content-Type: application/xml;charset=UTF-8
Link: http://server/error/someexplanation
<error>
<message>You have made an invalid request...
</message>
</error>
Demonstration
• A simple one page web application
http://mybooks.cloudfoundry.com/books.html
• Restful web service is implemented
using Jersey
• Client consumes the service through
JQUERY AJAX API and render the JSON
data
Test
Test RESTful Web Services
• Using cURL
Test RESTful Web Services
• Using cURL
Test RESTful Web Services
• Using cURL
Test RESTful Web Services
• Using SOAPUI
Test RESTful Web Services
• Using SOAPUI
Test RESTful Web Services
• Using SOAPUI
Test RESTful Web Services
• Using SOAPUI
Test RESTful Web Services
• Using SOAPUI
Reference
• http://www.ics.uci.edu/~fielding/pubs/
dissertation/top.htm
Books

More Related Content

PPTX
Building Software Backend (Web API)
PPTX
An Overview of Web Services: SOAP and REST
KEY
Library Mashups & APIs
PPTX
Soa 27 rest and restful services
PPTX
Ntg web services
PPTX
RESTful Web Service using Swagger
PPTX
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
PPTX
.Net Fundamentals
Building Software Backend (Web API)
An Overview of Web Services: SOAP and REST
Library Mashups & APIs
Soa 27 rest and restful services
Ntg web services
RESTful Web Service using Swagger
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
.Net Fundamentals

What's hot (20)

PPTX
Web services for banks
PPTX
Javascript on Server-Side
PDF
Elasticsearch JVM-MX Meetup April 2016
PPTX
RavenDB Presentation
PPTX
Drop acid
PPT
Document Databases & RavenDB
PPTX
MongoDB
PPTX
Austin Day of Rest - Introduction
PPTX
mongodb-brief-intro-february-2012
PPTX
Developing and Hosting REST APIs 3.7
PPTX
Building enterprise records management solutions for share point 2010
KEY
Using NoSQL MongoDB with ColdFusion
PPTX
The Ultimate Logging Architecture - You KNOW you want it!
PPTX
SharePoint 2013 APIs
PPTX
MongoDB - Getting Started
PPTX
Alfresco Tech Talk Live (Episode 70): Customizing Alfresco Share 4.2
PPTX
Basic Website 101
PDF
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
PPTX
SharePoint Saturday Utah - Do you claim to be from the Azure Sky?
KEY
MongoDB Administration ~ Kevin Hanson
Web services for banks
Javascript on Server-Side
Elasticsearch JVM-MX Meetup April 2016
RavenDB Presentation
Drop acid
Document Databases & RavenDB
MongoDB
Austin Day of Rest - Introduction
mongodb-brief-intro-february-2012
Developing and Hosting REST APIs 3.7
Building enterprise records management solutions for share point 2010
Using NoSQL MongoDB with ColdFusion
The Ultimate Logging Architecture - You KNOW you want it!
SharePoint 2013 APIs
MongoDB - Getting Started
Alfresco Tech Talk Live (Episode 70): Customizing Alfresco Share 4.2
Basic Website 101
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
SharePoint Saturday Utah - Do you claim to be from the Azure Sky?
MongoDB Administration ~ Kevin Hanson
Ad

Similar to Introduction to Restful Web Services (20)

PPTX
RESTful Services
PPTX
Mini-Training: Let's have a rest
PDF
Best Practices in Web Service Design
PPTX
PPTX
Rest APIs Training
PDF
REST API Recommendations
PPSX
Advanced Web Development in PHP - Understanding REST API
PPT
emilio.ppt
PPT
emilio.ppt
PPTX
Overview of REST - Raihan Ullah
PDF
Service-Oriented Design and Implement with Rails3
PDF
The Characteristics of a RESTful Semantic Web and Why They Are Important
PDF
Understanding REST-Based Services: Simple, Scalable, and Platform Independent
PPTX
Pragmatic REST APIs
PDF
REST API and CRUD
PDF
What is REST?
PDF
Best Practice in Web Service Design
PPTX
RESTful services
PDF
RESTful web
PDF
On being RESTful
RESTful Services
Mini-Training: Let's have a rest
Best Practices in Web Service Design
Rest APIs Training
REST API Recommendations
Advanced Web Development in PHP - Understanding REST API
emilio.ppt
emilio.ppt
Overview of REST - Raihan Ullah
Service-Oriented Design and Implement with Rails3
The Characteristics of a RESTful Semantic Web and Why They Are Important
Understanding REST-Based Services: Simple, Scalable, and Platform Independent
Pragmatic REST APIs
REST API and CRUD
What is REST?
Best Practice in Web Service Design
RESTful services
RESTful web
On being RESTful
Ad

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
cuic standard and advanced reporting.pdf
Modernizing your data center with Dell and AMD
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation

Introduction to Restful Web Services