Slide 1

Slide 1 text

REST API Development ABU ASHRAF MASNUN

Slide 2

Slide 2 text

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?

Slide 3

Slide 3 text

REST API: Benefits ● Decoupling the client and the server ● Serving many different type of clients ● Server changes don’t require client changes ● Easily scalable

Slide 4

Slide 4 text

REST Structure ● /users/ ● /users/1/ ● /users/1/photos/ ● /users/1/photos/23/ HTTP Methods: ● GET ● POST ● PUT ● PATCH ● DELETE

Slide 5

Slide 5 text

How I do things ● Resource ● Nested resource (relations) ● Singular or plural? ● Those who are not REST? ○ Star / Unstar? ○ Search?

Slide 6

Slide 6 text

● Versioning ○ Header vs URL ● Filtering / Sorting ○ Using common queries in the url ● Limiting fields ● Content negotiation ○ JSON vs XML ○ Header vs URL

Slide 7

Slide 7 text

● 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

Slide 8

Slide 8 text

● Rate Limiting ○ Why? ○ 429 - too many requests ○ Let the client know - use a header ● Caching ○ Etag - If None Match ○ Last modified - If Modified Since

Slide 9

Slide 9 text

● Handling errors ○ Return an error code ○ A Message ○ A Detailed description ● Documentation ● Scaling APIs ● SSL

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Questions