REST
-
Roy Fielding defined REST
("Representational state transfer")
as the style of architecture used in (the already-existing) HTTP.
-
Similar APIs are called "REST-ful" APIs.
- RESTful systems
typically communicate over HTTP
with the basic
HTTP methods
(GET, POST, PUT, etc.)
Properties of RESTful systems
See
Ch.5
of Roy Fielding's PhD.
Properties of RESTful systems:
- Client-server model.
Data storage on server only.
UI on client only.
- Stateless.
Basic
HTTP model is stateless. One URL request has no relation to later URL request.
There are ways to keep state on Web
though.
Built on top of a stateless protocol.
- Cacheable.
The HTTP model aims to reduce duplicate requests by caching data on client.
It builds in a model where responses can be defined as cachable or not.
See
"Cache-Control" in
HTTP headers.
- Uniform interface to resources:
- Resource address passed in request.
Web uses URLs as universal address of resources (same address for each client to use).
See
URI schemes
on Web.
- Response contains description of resource type.
See
MIME types.
- HATEOAS
("Hypermedia as the Engine of Application State")
Hypermedia-like system.
Responses contain addresses for further resources.
(Page contains links to more pages.)
- Layered system.
Intermediate servers can be introduced between client and server. Can do caching, security.
See
Proxy servers
on the Web.
He adds as optional:
- Code-On-Demand.
Client does not need to install applications in advance. Client stays simple.
Server sends code to client to implement functionality at run-time.
See
JavaScript.
Read-write RESTful systems
Some
RESTful systems
may be primarily
read-write systems.
The normal Web
is mixed (large parts read-only,
other parts read-write).
In general:
Say we have collections of resources,
and an individual resource is a member of a collection,
in a read-write system.
We might define our RESTful API methods as follows.
Method call |
What it does |
Permanent effect |
GET (collection URI) |
List URIs of members of collection
e.g. See
Readable web directories
|
No |
PUT (collection URI) |
Replace entire collection with uploaded data |
Yes |
POST (collection URI) |
Add new element to collection |
Yes |
DELETE (collection URI) |
Delete entire collection |
Yes |
GET (member URI) |
Client retrieves copy of member of collection |
No |
PUT (member URI) |
Replace member with uploaded data |
Yes |
DELETE (member URI) |
Delete member |
Yes |