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    (and good HTTP semantics)
  • 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.

{
    "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"
      }
    ]
}

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!

Intro to REST

By Shelby Switzer

Loading comments...

More from Shelby Switzer