REST API

Representational State Transfer. It's a set of rules for how computers talk to each other over the web. It treats everything as a Resource (a noun) that you can act upon using Verbs.

đŸŊī¸ The Waiter Analogy

💁

You (Client): You are hungry. You look at the Menu (Documentation).

Waiter (API): Takes your order to the kitchen. You don't know how the kitchen works; you just talk to the waiter.

Kitchen (Server/DB): Cooks the food (Data) and gives it back to the waiter.

GET

Retrieve data.
Like reading a blog post or viewing a profile. Safe to run multiple times (Idempotent).

POST

Create data.
Like submitting a signup form. Adds a new entry to the database.

PUT / PATCH

Update data.
PUT replaces the whole object. PATCH just updates one field (like changing your password).

DELETE

Remove data.
Like deleting a photo. It's gone forever.

đŸ•šī¸ API Laboratory

Mission: You are the Client. Interact with the "Users" database.
Try: GET to see all, POST to add yourself, or DELETE user #1.

Request Builder
https://api.app.com
Server Response
Ready
...
Database State (users_table)

đŸšĨ Status Codes

2xx Success

  • 200 OK: It worked.
  • 201 Created: New thing made (POST).

4xx Client Error

  • 400 Bad Request: You sent garbage.
  • 401 Unauthorized: Who are you?
  • 404 Not Found: It's not here.

5xx Server Error

  • 500 Internal Error: The kitchen is on fire.
  • 503 Unavailable: Server is overloaded.