API Fundamentals Course
API Fundamentals
/
Beginner

Resources & Endpoints

Definition

In REST, a 'Resource' is any piece of data or object the API exposes (like Users, Posts, Comments). An 'Endpoint' is the specific URL URL where that resource can be accessed.

Explain Like I'm New

Think of a Resource as a noun (a Book). Think of an Endpoint as the physical address of the library bookshelf where that book lives (`api.library.com/books/123`).

Real World Example

In a Twitter clone API, the Resources are `users`, `tweets`, and `likes`. The Endpoints are `api.com/users`, `api.com/tweets`, and `api.com/tweets/5/likes`.

Common Use Cases

  • •API Routing
  • •Database modeling

Terminal Output

bash / terminal
/* Resource Naming Conventions in REST */ // Rule 1: Use plural nouns āœ… GET /tickets āŒ GET /ticket // Rule 2: Do not use verbs in the URL (The HTTP method IS the verb) āœ… POST /users āŒ POST /createUser // Rule 3: Use nesting to show relationships (Sub-resources) // "Get all reviews for product #55" āœ… GET /products/55/reviews // Rule 4: Don't nest too deeply (Keep it flat if possible) āŒ GET /users/1/orders/5/items/32/tracking āœ… GET /items/32/tracking

Interview Questions

basic

  • In REST API design, should URLs be based on Nouns or Verbs?

intermediate

  • How do you represent a relationship between two resources in an endpoint URL (e.g., the comments belonging to a specific article)?

Flash Cards

Question

Nouns or Verbs?

Click to reveal answer
Answer

Nouns! `GET /users` is correct. `GET /getUsers` is a violation of REST principles.

Question

Represent relationships?

Click to reveal answer
Answer

By nesting the resources in the URL path: `/articles/123/comments`.