Best Practice in API Design
About Me

 • Lorna Jane Mitchell

 • http://lornajane.net

 • PHP consultant, developer, trainer

 • Author, speaker




                                        2
Using APIs

There are various stages:

  1. publish




                            3
Using APIs

There are various stages:

  1. publish

  2. dogfood




                            3
Using APIs

There are various stages:

  1. publish

  2. dogfood

  3. modularity




                            3
Web
Service
Design
Web
HTTP
Request and Response
Statelessness
Status Codes
Status Codes: Headline News

Common codes:

                200   OK
                302   Found
                301   Moved
                401   Not Authorised
                403   Forbidden
                404   Not Found
                500   Internal Server Error




                                              12
Headers
HTTP Headers

Headers are the metadata about the content we send/receive

Useful headers:

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




                                                                   14
Content Negotiation
HTTP Headers

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




                                                                   16
HTTP Headers

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




                                                                   16
HTTP Headers

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




                                                                   16
Access Control
Verbs
HTTP Verbs

  • More than GET and POST

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

  • HEAD, OPTIONS and others also specified

                     GET    Read
                    POST    Create
In REST, we use:
                     PUT    Update
                   DELETE   Delete




                                                               19
Service
Target Audience
Heartbeat
RPC Services
RPC: Remote Procedure Call

 • Single endpoint

 • Function name

 • Parameters

 • Return value

 • SOAP is a kind of RPC




                             24
Soap
Data Formats
Small APIs
REST
RESTful Services

 • 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




                                                           29
Design
Versioning
Consistency
Handling Errors
Delivery and Support
Web Service Design
Thanks!




          https://joind.in/6385
               @lornajane
          http://lornajane.net/




                                  36

Best Practice in API Design