Top Banner
Best Practice in API Design
40

Best Practice in API Design

May 19, 2015

Download

Technology

Lorna Mitchell

"Best Practice in API Design" talk given at phpday 2012 in Verona, Italy. This talk aims to give the best possible advice to anyone publishing a web service of any kind.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Best Practice in API Design

Best Practice in API Design

Page 2: Best Practice in API Design

About Me

2

• Lorna Jane Mitchell

• http://lornajane.net

• PHP consultant, developer, trainer

• Author, speaker

Page 3: Best Practice in API Design

Using APIs

3

There are various stages:

1. publish

Page 4: Best Practice in API Design

Using APIs

3

There are various stages:

1. publish

2. dogfood

Page 5: Best Practice in API Design

Using APIs

3

There are various stages:

1. publish

2. dogfood

3. modularity

Page 6: Best Practice in API Design

Web

Page 7: Best Practice in API Design

Service

Page 8: Best Practice in API Design

Design

Page 9: Best Practice in API Design

Web

Page 10: Best Practice in API Design

HTTP

Page 11: Best Practice in API Design

Request and Response

Page 12: Best Practice in API Design

Statelessness

Page 13: Best Practice in API Design

Status Codes

Page 14: Best Practice in API Design

Status Codes: Headline News

12

Common codes:

200 OK

302 Found

301 Moved

401 Not Authorised

403 Forbidden

404 Not Found

500 Internal Server Error

Page 15: Best Practice in API Design

Headers

Page 16: Best Practice in API Design

HTTP Headers

14

Headers are the metadata about the content we send/receive

Useful headers:

• Accept and Content-Type: used for content format negotiation

Page 17: Best Practice in API Design

Content Negotiation

Page 18: Best Practice in API Design

HTTP Headers

16

Headers are the metadata about the content we send/receive

Useful headers:

• Accept and Content-Type: used for content format negotiation

• User-Agent: to identify what made the request

Page 19: Best Practice in API Design

HTTP Headers

16

Headers are the metadata about the content we send/receive

Useful headers:

• Accept and Content-Type: used for content format negotiation

• User-Agent: to identify what made the request

• Set-Cookie and Cookie: working with cookie data

Page 20: Best Practice in API Design

HTTP Headers

16

Headers are the metadata about the content we send/receive

Useful headers:

• Accept and Content-Type: used for content format negotiation

• User-Agent: to identify what made the request

• Set-Cookie and Cookie: working with cookie data

• Authorization: controlling access

Page 21: Best Practice in API Design

Access Control

Page 22: Best Practice in API Design

Verbs

Page 23: Best Practice in API Design

HTTP Verbs

19

• More than GET and POST

• PUT and DELETE to update and delete in a RESTful service

• HEAD, OPTIONS and others also specified

In REST, we use:

GET Read

POST Create

PUT Update

DELETE Delete

Page 24: Best Practice in API Design

Service

Page 25: Best Practice in API Design

Target Audience

Page 26: Best Practice in API Design

Heartbeat

Page 27: Best Practice in API Design

RPC Services

Page 28: Best Practice in API Design

RPC: Remote Procedure Call

24

• Single endpoint

• Function name

• Parameters

• Return value

• SOAP is a kind of RPC

Page 29: Best Practice in API Design

Soap

Page 30: Best Practice in API Design

Data Formats

Page 31: Best Practice in API Design

Small APIs

Page 32: Best Practice in API Design

REST

Page 33: Best Practice in API Design

RESTful Services

29

• REpresentational State Transfer

• URLs are unique resource identifiers

• HTTP verbs indicate which operation should happen

• We have full CRUD operations on a series of resources

Page 34: Best Practice in API Design

Design

Page 35: Best Practice in API Design

Versioning

Page 36: Best Practice in API Design

Consistency

Page 37: Best Practice in API Design

Handling Errors

Page 38: Best Practice in API Design

Delivery and Support

Page 39: Best Practice in API Design

Web Service Design

Page 40: Best Practice in API Design

Thanks!

36

https://joind.in/6385

@lornajane

http://lornajane.net/