Rest Services
REST philosophy
What is REST?
REST is an easy to understand design style derived from the evolution of the World Wide Web. REST queries are usually HTTP-queries with HTML or XML payload. REST is perhaps the easiest to implement and deploy, especially when compared to
SOAP/RPC-based services with heavy frameworks and
multiple supporting standards.
REST philosophy
What is REST?
REST itself is a hybrid concept style of different styles adopted from older techniques with the big exception of having a uniform connector interface to operate with.
An architectural style of networked systems (Not a protocol - Not a specification)
Objective: Expose resources on a networked system (the Web) Principles:
Resource Identification using a URI (Uniform Resource Identifier) Unified resource interface to retrieve, create, delete or update resources REST itself is not an official standard or even a recommendation. It is just a ”design guideline”
REST philosophy
What is a Resource?
A resource is a thing that:
is unique (i.e., can be identified uniquely) has at least one representation,
has one or more attributes beyond ID has a potential schema, or definition can provide context
is reachable within the addressable universe
REST philosophy
What is a Resource?
Resource Presentation
Origins of REST
REST is an acronym standing for Representational State Transfer.
First introduced by Roy T. Fielding in his PhD dissertation
”Architectural Styles and the Design of Network-based Software Architectures”
He focused on the rationale behind the design of the modern Web architecture and how it differs from other architectural styles.
REST is client-server where a representation of the resource is exposed to the client application.
The representation of resources places the client application in a state.
Such state is evolving with each resource representation through traversing hyperlinks
REST principles: Resource Identification
Resources are identified by a URI (Uniform Resource Identifier)
Most known URI type are URL and URN URN (Uniform Resource Name)
urn:isbn:0-486-27557-4 URL (Uniform Resource Locator)
file:///home/username/RomeoAndJuliet.pdf
REST principles: Uniform Interface
The REST Uniform Interface Principle consider four (4) operations on resources:
PUT: Initialize the state of a new resource at the given URI GET: Retrieve the current state of the resource. It is a read-only operation. It can be repeated without affecting the state of the resource (idempotent)
POST: Modify the state of a resource. POST is a read-write operation and may change the state of the resource and provoke side effects on the server. Web browsers warn you when refreshing a page generated with POST.
DELETE: Clear a resource, after the URI is no longer valid
Similar to the CRUD (Create, Read, Update, Delete) databases operations
REST principles: Uniform Interface
REST Examples
REST Examples
REST Web Services
RESTful Web services show you how to use [the principles of the Web] without the big words that have scared a generation of web developers into thinking that Web services are so hard that you have to rely on BigCo implementations to get anything done.
REST Services Characteristics
REST Services by Example (1)
REST Services by Example (2)
REST Services by Example (3)
REST Services by Example (4)
Get a listing of employees as Atom feed:
http://www.myserver.com/atom/feed/employees (GET) Get a single employee’s XML record:
/atom/content/employees?/ssakr (GET) Add a new employee to a collection
/atom/feed/employees (POST) Get a picture of an employee
/atom/image/employees?/ssakr (GET) Update an employee’s record:
/atom/feed/employees?/ssakr (PUT) Delete an employee:
/atom/feed/employees?/ssakr (DELETE)
REST Services by Example (5)
REST Services by Example (6)
REST Services by Example (8)
Resource Representation Formats
XML (RSS, ATOM, ...)
Standard textual syntax for semi-structured data
Managed within several tools like XML Schema, DOM, SAX, XPath, XSLT, XQuery, ...
Easy to parse but not easy to understand
Slow and Verbose
Resource Representation Formats
JSON
JavaScript Object Notation (JSON)
Wire format introduced for AJAX (Asynchronous JavaScript + XML).
It became the X in AJAX
Web applications (Browser-Web Server communication)
Textual syntax for serialization of non-recurrent data structures
Supported in most languages (not only JavaScript)
REST Complex Queries
Principles of REST Web Service Design
Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
http://www.parts-depot.com/parts/getPart?id=00345 Note the verb, getPart. Instead, use a noun:
http://www.parts-depot.com/parts/00345
Categorize resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
All resources accessible via HTTP GET should be side-effect free.
That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
One API for All
Building REST Web services
Building REST Web services(Example using a servlet)
Building REST Web services (XML, CSV and JSON
supported resource formats)
Building REST Web services (Implementing an XML reply)
Building REST Web services (Implementing a CSV reply)
Building REST Web services (Implementing a JSON reply)
When can I use REST?
For Web Services
build your web service using the REST style
alternative to some of WS-*, not a replacement for WS-*
Clients interfacing to public REST APIs
e.g. Amazon S3 REST API, Google Data APIs Many other public APIs have a REST like interface From Rich Internet Applications (RIAs)?
client sends AJAX requests to a REST interface using a JavaScript library e.g. jQuery, Dojo (JsonRestStore) or a framework like JavaFX or Silverlight
response (JSON, XML etc) is displayed on the client
REST Resources
RESTWiki - http://internet.conveyor.com/RESTwiki/moin.cgi/
REST mailing list - http://groups.yahoo.com/group/rest-discuss/
Roy Fielding’s Dissertation
http://www.ics.uci.edu/∼fielding/pubs/dissertation/fielding dissertation.pdf