Restful design at work v2.0

57
RESTful Design at Work Tom Marrs Architect

description

Slides for Tom Marrs BJUG talk on 2/12/2013. See http://boulderjug.org/2013/01/tuesday-february-12-2013-a-night-with-tom-marrs-covering-json-and-rest.html

Transcript of Restful design at work v2.0

Page 1: Restful design at work v2.0

RESTful Design at WorkTom MarrsArchitect

Page 2: Restful design at work v2.0

Your ProfileHow?

What?

Where?

Page 3: Restful design at work v2.0

What’s The Point?

Interface

Design

Matters

Page 4: Restful design at work v2.0

Our Agenda

RESTful Web Service

Best Practices

RESTful Web Service Design

Guidelines

RESTful API

Sources

Well-Designed RESTful

APIs

Page 5: Restful design at work v2.0

We’re Not Covering :(-

Security

Lots of Code

SOA

Design Patterns

Page 6: Restful design at work v2.0

RESTful Design Best Practices - Roadmap

Page 7: Restful design at work v2.0

Determine Data Set

Business Context

Requirements

Models

Page 8: Restful design at work v2.0

Our Case Study - Mentoring Program

A Relationship

6 meetings

Face-to-face or Phone

Mentoring Checklist

Page 9: Restful design at work v2.0

Mentoring Program - User Stories

Page 10: Restful design at work v2.0

Discover Resources

Type Example

Things Order, Member, Product

Associations Enrollment, Membership, Marriage, Employment

Processes Onboarding, Underwriting, Mentoring

Functions Driving Directions, Search

Page 11: Restful design at work v2.0

Design Resources

Page 12: Restful design at work v2.0

Uniform Interface - HTTP Methods/VerbsHTTP Verb/

Method Action

GET Read

POST Create [Update]

PUT Update [Create]

DELETE Delete

Page 13: Restful design at work v2.0

HTTP Status Codes - Typical

HTTP Verb/Method

HTTP Status Code

Meaning

GET 200 OK

GET 404 Not Found

POST 201 Created

PUT 200 OK

PUT 404 Not Found

PUT 409 Conflict

DELETE 200 OK

DELETE 404 Not Found

DELETE 409 Conflict

Page 14: Restful design at work v2.0

HTTP Status Codes - Other

HTTP Verb/Method

HTTP Status Code

Meaning

POST / PUT / DELETE 202 Accepted - Process request later

POST / PUT / DELETE 204 No Content

GET / PUT / DELETE 301 Moved Permanently

ALL 400 Bad Request

ALL 401 Unauthorized

ALL 500 Internal Server Error

Page 15: Restful design at work v2.0

Design URIs

Page 16: Restful design at work v2.0

Of Nouns and Verbs

Nouns - Good

Verbs - Bad

Page 17: Restful design at work v2.0

Verbs - Really Bad!/listPairs/reviewPairStatus/deletePair/updateProgress.../getAvgWaitTimeForMember - Really??/provideMemberFeedback/provideMentorFeedback

Page 18: Restful design at work v2.0

Of Nouns and Verbs ... Cont’d

Page 19: Restful design at work v2.0

Use Parameters -Simplify Associations

Before (Update Progress)/pairs/{pairId}/mentor/{mentorId}

After (Update Progress)/pairs/{pairId}?mentor={mentorId}

Page 20: Restful design at work v2.0

Pagination

API Pagination Params

Facebook ?offset=100&limit=25

Twitter ?page=5&rpp=25

LinkedIn ?start=100&count=25

Recommended /members?offset=100&limit=25

Page 21: Restful design at work v2.0

SearchingGlobal

/search?q=Fred+Smith

Scoped /search/mentors/32/feedback/q?=leader

Page 22: Restful design at work v2.0

Versioning

API Sample URI

Twilio /2012-07-11/Accounts/{AccountSid}

SalesForce.com /services/data/v20.0/sobjects/Account

Facebook ?v=1.0

Recommended /v2/members

Page 23: Restful design at work v2.0

Versioning ... Cont’d

Change Don’t Change

Deleted / Renamed Resources New Resources

Removed HTTP Methods New HTTP Methods

Different Data (same URI) New Data Formats

New Attributes / Data Elements

Page 24: Restful design at work v2.0

Content Negotiation

Format HTTP Request

JSON

Accept Header - application/json

simplytoast.api/members/243.json

XML

Accept Header - application/xml

simplytoast.api/members/243.xml

Page 25: Restful design at work v2.0

Error Handling

HTTP Status Codes

Error Messages?

Page 26: Restful design at work v2.0

Error Messages? Why or Why Not?

{ "status" : { "user" : { "message" : "Member Fred Smith already exists." }, "dev" : { "code" : 409, "message" : "Member exists. Only a DELETE or UPDATE is possible at this point." } }}

Page 27: Restful design at work v2.0

JSON Object Design - JSONPad

Page 28: Restful design at work v2.0

How to Spot a Hybrid

Page 29: Restful design at work v2.0

Reddit

Page 30: Restful design at work v2.0

Flickr

Page 32: Restful design at work v2.0

Delicious

Page 33: Restful design at work v2.0

RESTful Web Service Design Guidelines

Alfresco

Apigee

Atlassian

Page 34: Restful design at work v2.0

Alfresco

Page 35: Restful design at work v2.0

Apigee

Page 36: Restful design at work v2.0

Atlassian

Page 37: Restful design at work v2.0

Well-Designed RESTful APIs

Twitter

LinkedInOpen Library

Twilio

Page 38: Restful design at work v2.0

LinkedIn - People

Page 39: Restful design at work v2.0

Twilio - Send SMS

Page 40: Restful design at work v2.0

REST API Sources - ProgrammableWeb

Page 41: Restful design at work v2.0

REST API Sources - ProgrammableWeb

Page 42: Restful design at work v2.0

REST API Sources - BART API Docs

Page 43: Restful design at work v2.0

REST API Sources - BART ETA API

Page 44: Restful design at work v2.0

REST API Sources - BART-RESTClient

Page 45: Restful design at work v2.0

Other RESTful APIs

Groupon

GitHub

Page 46: Restful design at work v2.0

Roll Your Own RESTful API - Dyson

Page 47: Restful design at work v2.0

Our Agenda

RESTful Web Service

Best Practices

RESTful Web Service Design

Guidelines

RESTful API

Sources

Well-Designed RESTful

APIs

Page 48: Restful design at work v2.0

What’s The Point?

Interface

Design

Matters

Page 51: Restful design at work v2.0

RESTful GroupsAPI Craft - http://groups.google.com/group/api-craft/topics

REST Discuss - http://tech.groups.yahoo.com/group/rest-discuss/

Page 52: Restful design at work v2.0

REST in Practice

Page 53: Restful design at work v2.0

RESTful Web Services

Page 54: Restful design at work v2.0

RESTful Web Services Cookbook

Page 55: Restful design at work v2.0

REST API Design Handbook

Page 56: Restful design at work v2.0

RESTful Java with JAX-RS

Page 57: Restful design at work v2.0

REST API Design Rulebook