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

REST API Development

REST API Development

Abu Ashraf Masnun

January 12, 2023
Tweet

More Decks by Abu Ashraf Masnun

Other Decks in Programming

Transcript

  1. Why do we need REST APIs? Let’s build the next

    Instagram to better understand this! • We need a web app • We need an Android App • We need an iOS App • We want a desktop app too How should we approach this problem?
  2. REST API: Benefits • Decoupling the client and the server

    • Serving many different type of clients • Server changes don’t require client changes • Easily scalable
  3. REST Structure • /users/ • /users/1/ • /users/1/photos/ • /users/1/photos/23/

    HTTP Methods: • GET • POST • PUT • PATCH • DELETE
  4. How I do things • Resource • Nested resource (relations)

    • Singular or plural? • Those who are not REST? ◦ Star / Unstar? ◦ Search?
  5. • Versioning ◦ Header vs URL • Filtering / Sorting

    ◦ Using common queries in the url • Limiting fields • Content negotiation ◦ JSON vs XML ◦ Header vs URL
  6. • Snake Case vs Camel Case for field names •

    Pretty print • Enable gzip • Embed relevant data • Overriding HTTP Methods ◦ Use a header to determine which method to override ◦ Always use POST
  7. • Rate Limiting ◦ Why? ◦ 429 - too many

    requests ◦ Let the client know - use a header • Caching ◦ Etag - If None Match ◦ Last modified - If Modified Since
  8. • Handling errors ◦ Return an error code ◦ A

    Message ◦ A Detailed description • Documentation • Scaling APIs • SSL
  9. Status Codes • 2xx - Alright mate ◦ 200 -

    ok ◦ 201 - created ◦ 204 - no content • 3xx - Not here ◦ 300, 301 - moved ◦ 304 - not modified • 4xx - You fucked up ◦ 400 - bad request ◦ 401 - unauthorized ◦ 404 - not found • 5xx - We fucked up ◦ 500 - internal server error