Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Everything I've Learned About APIs But Been Too...

Everything I've Learned About APIs But Been Too Afraid To Talk About... Until Now

Slide deck from the talk on APIs I gave at Laravel Live UK 2024.

Michael Price

June 27, 2024
Tweet

Other Decks in Programming

Transcript

  1. WHAT’S THIS TALK ABOUT? • WHAT APIS ARE USED FOR

    • WHAT TO DO - AND WHAT NOT TO DO • …WHETHER CREATING OR CONSUMING • BEST PRACTICES • TIPS AND TRICKS
  2. WHAT IS AN API? • APPLICATION PROGRAMMING INTERFACE • A

    WAY FOR TWO APPLICATIONS TO “TALK” TO EACH OTHER • AN “APPLICATION” CAN BE SOFTWARE, SUCH AS A WEBSITE, OR MOBILE APP… • …OR HARDWARE SUCH AS A CARD TERMINAL OR SMART SPEAKER
  3. WHAT IS AN API? • APIS EXPOSE ENDPOINTS • YOUR

    APPLICATION CALLS THESE ENDPOINTS TO GET, CREATE OR UPDATE DATA
  4. COMMON API TYPES • REST • REPRESENTATIONAL STATE TRANSFER •

    FLEXIBLE PAYLOADS (JSON, XML, PLAIN TEXT ETC.)
  5. USE THE RIGHT REQUEST METHOD - retrieve a list of

    resources - retrieve a speci fi c resource - create a new resource - replace a resource - update a resource - delete a resource
  6. USE THE RIGHT HEADERS • Accept AND Content-Type • USEFUL

    IF AN API CAN OUTPUT MULTIPLE CONTENT TYPES
  7. USE THE RIGHT STATUS CODES • 200 OK • 201

    Created • 202 Accepted • 204 No Content 2xx - THE GOOD ONES
  8. USE THE RIGHT STATUS CODES • 301 Permanent Redirect •

    302 Temporary Redirect • 304 Not Modified • 307 Permanent Redirect • 308 Temporary Redirect 3xx - THE INFORMATIONAL ONES
  9. USE THE RIGHT STATUS CODES • 400 Bad Request •

    401 Unauthorised • 403 Forbidden • 404 Not Found 4xx - THE CLIENT ERRORS
  10. USE THE RIGHT STATUS CODES • 405 Method Not Allowed

    • 429 Too Many Requests • 418 I’m a teapot 4xx - THE CLIENT ERRORS
  11. USE THE RIGHT STATUS CODES • 500 Internal Server Error

    • 502 Bad Gateway • 503 Service Unavailable • 504 Gateway Timeout 5xx - THE SERVER ERRORS
  12. DOCUMENTATION • BE THOROUGH • INCLUDE EXAMPLE PAYLOADS • INCLUDE

    EXAMPLE RESPONSES • USE THE OPENAPI SPEC • CONSIDER PROVIDING AN SDK • …AND A SANDBOX / PLAYGROUND
  13. Q+A