Chris Dail - @chrisdail
Director, Software Engineering at EMC
http://chrisdail.github.io/talk-pragmatic-rest-api-design/
We love to think our products will solve all customer problems but this is not realistic
Representational State Transfer
“HTTP based RESTful APIs are defined with these aspects: base URI, such as http://example.com/resources/ an Internet media type for the data. This is often JSON but can be any other valid Internet media type (e.g. XML, Atom, microformats, images, etc.) standard HTTP methods (e.g., GET, PUT, POST, or DELETE)” - Wikipedia
/widgets
/storage-systems # Storage or Systems is not specific enough
/foo/things # 'foo' component allows multiple /things
/resources?type=volume
/widgets?limit=100
/foo/things?tenant=coke
/widgets?q=frank
"things: [
{ },
{ }
]
<things>
<thing></thing>
<thing></thing>
</things>
// This
"size_gb": 10
// Not this
"size": "10gb"
yyyy-mm-dd'T'hh[:mm]
GET /widgets/12
Link: <https://host/v1/widgets/12/knobs>; rel="knobs"
GET /widgets?limit=100
Link: </widgets?limit=100&offset=100>; rel="next",
</widgets?limit=100&offset=22300>; rel="last"
GET /widgets?limit=100
Link: </widgets?limit=100&marker=id123>; rel="next"
Accepts: application/vnd.widgets+json; version="1"
https://hostname/v1/widgets/12
POST /widgets/12
{
"code": 9001,
"message": "Error updating resource",
"details": "Error updating resource with ID 12 because of bla"
}
POST /widgets/12
{
"code": "9001",
"message": "Validation Error",
"details": "Validation error with the hostname field"
"fields": [
{
"name": "hostname",
"code": "2001",
"message": "Hostname field not specified but is required"
}
]
}
ETag
header. If-None-Match
Last-Modified
header. If-Modified-Since