WTF is REST?
@switzerly
shelbyswitzer.com
WTF does this have to do with REST?
1. Starting with Null State
2. Client-Server
3. Cache
4. Stateless
5. Uniform Interface
6. Layered System
The RESTful Interface
- Identification of resources
- Manipulation of resources through representations
- Self-descriptive messages
- Hypermedia As The Engine Of Application State (HATEOAS)
{
"total_items": 1,
"total_pages": 1,
"items": [
{
"id": "CARD-1SV265177X389440GKLJZIYY",
"state": "ok",
"payer_id": "user12345",
"type": "visa",
"number": "xxxxxxxxxxxx0331",
"first_name": "Joe",
"last_name": "Shopper",
"valid_until": "2017-01-12T00:00:00Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "delete",
"method": "DELETE"
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/?page_size=10&sort_by=create_time&sort_order=asc",
"rel": "first",
"method": "GET"
}
]
}
It's all about representations.
POST /v1/vault/credit-cards
{
"payer_id": "user12345",
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"first_name": "Betsy",
"last_name": "Buyer",
"billing_address": {
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}
}
{
"total_items": 1,
"total_pages": 1,
"items": [
{
"id": "CARD-1SV265177X389440GKLJZIYY",
"state": "ok",
"payer_id": "user12345",
"type": "visa",
"number": "xxxxxxxxxxxx0331",
"first_name": "Joe",
"last_name": "Shopper",
"valid_until": "2017-01-12T00:00:00Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "delete",
"method": "DELETE"
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/?page_size=10&sort_by=create_time&sort_order=asc",
"rel": "first",
"method": "GET"
}
]
}
{
"total_items": 1,
"total_pages": 1,
"items": [
{
"id": "CARD-1SV265177X389440GKLJZIYY",
"state": "ok",
"payer_id": "user12345",
"type": "visa",
"number": "xxxxxxxxxxxx0331",
"first_name": "Joe",
"last_name": "Shopper",
"valid_until": "2017-01-12T00:00:00Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "self",
"method": "GET"
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/?page_size=10&sort_by=create_time&sort_order=asc",
"rel": "first",
"method": "GET"
}
]
}
{
"total_items": 1,
"total_pages": 1,
"items": [
{
"id": "CARD-1SV265177X389440GKLJZIYY",
"state": "ok",
"payer_id": "user12345",
"type": "visa",
"number": "xxxxxxxxxxxx0331",
"first_name": "Joe",
"last_name": "Shopper",
"valid_until": "2017-01-12T00:00:00Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-1SV265177X389440GKLJZIYY",
"rel": "update",
"method": "PUT"
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/vault/credit-cards/?page_size=10&sort_by=create_time&sort_order=asc",
"rel": "first",
"method": "GET"
}
]
}
W(ho)TF uses REST?
Rails Routes
burritos GET /burritos(.:format)
POST /burritos(.:format)
burrito GET /burritos/:id(.:format)
PATCH /burritos/:id(.:format)
PUT /burritos/:id(.:format)
DELETE /burritos/:id(.:format)
Know your customer.
Good HTTP Semantics
& Architectural Practices
- Use status codes correctly
- HTTP verbs are your friend
- Headers a f***ing useful
- No verbs in URLs!
- Focus on resources
- Keep business logic on the server
Resources
- Fielding's thesis (where we got this sh*t): https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
- http://timelessrepo.com/haters-gonna-hateoas
- http://blog.steveklabnik.com/posts/2012-02-27-hypermedia-api-reading-list
-
http://blog.apiary.io/2015/06/09/Decoupling-the-Mind-of-the-API-Designer/
-
http://hallwayconversations.com/podcast/episode-048-a-lap-around-rest-with-mike-amundsen/
-
http://www.apiacademy.co/client-optimized-resource-representations-in-apis/
-
http://intellyx.com/2015/07/20/are-microservices-soa-done-right/
- http://www.infoq.com/articles/description-discovery-profiles-series-intro
- https://github.com/paypal/api-standards/blob/master/api-style-guide.md
Tweet at me, yo!
@switzerly
THANKS!
WTF is REST? - WWC
By Shelby Switzer
WTF is REST? - WWC
- 1,726