Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

REST API Design Reference cheat sheet - grade 10-12

Click image to open full size

REST API design is about creating web endpoints that let software systems exchange data in a predictable way. This cheat sheet helps students remember how resources, routes, HTTP methods, and responses fit together. It is useful for building projects, reading API documentation, and understanding how modern web apps communicate. Clear API design makes programs easier to test, maintain, and use. The most important ideas are to name resources with nouns, use HTTP methods for actions, and return meaningful status codes. Good endpoints are consistent, readable, and focused on one resource or collection. Requests and responses usually use JSON, with clear fields and error messages. Design choices like pagination, filtering, versioning, and authentication help APIs stay reliable as they grow.

Key Facts

  • Use nouns for resource paths, such as /users or /orders/42, instead of verbs like /getUsers.
  • GET retrieves data, POST creates a new resource, PUT replaces a resource, PATCH updates part of a resource, and DELETE removes a resource.
  • A collection endpoint uses a plural noun, such as GET /products, while a single-resource endpoint includes an id, such as GET /products/17.
  • Successful responses commonly use 200 OK for reads or updates, 201 Created for new resources, and 204 No Content for successful deletes with no body.
  • Client error responses commonly use 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, and 409 Conflict.
  • Pagination can use query parameters like GET /articles?page=2&limit=20 to return a smaller part of a large collection.
  • Filtering and sorting belong in query strings, such as GET /books?author=Lee&sort=title.
  • API versioning can be placed in the path, such as /v1/users, or in headers, but it should be consistent across the API.

Vocabulary

REST
REST is an architectural style for designing web APIs around resources, standard HTTP methods, and stateless requests.
Resource
A resource is an object or collection that an API exposes, such as a user, order, message, or list of products.
Endpoint
An endpoint is a specific URL path and method combination that clients use to access or change a resource.
HTTP Method
An HTTP method is the action word of a request, such as GET, POST, PUT, PATCH, or DELETE.
Status Code
A status code is a three-digit number in an HTTP response that tells the client whether the request succeeded or failed.
JSON
JSON is a text-based data format commonly used to send structured request and response data in APIs.

Common Mistakes to Avoid

  • Using verbs in endpoint names, such as /createUser, is wrong because REST paths should represent resources while HTTP methods represent actions.
  • Returning 200 OK for every response is wrong because clients need accurate status codes to handle success, validation errors, missing resources, and permission problems.
  • Putting filters into path segments, such as /books/author/Lee, can become confusing because optional search conditions usually belong in query parameters like /books?author=Lee.
  • Changing server state with GET is wrong because GET requests should be safe and should not create, update, or delete data.
  • Sending unclear error messages is wrong because clients need a predictable error format, such as {"error":"Invalid email","field":"email"}, to fix requests.

Practice Questions

  1. 1 Write the best REST endpoint and HTTP method to retrieve the order with id 58.
  2. 2 A client successfully creates a new product by sending POST /products. Which status code should the API usually return?
  3. 3 Choose the better endpoint for listing the second page of books with 25 results per page: /getBooksPage2Limit25 or /books?page=2&limit=25. Explain your choice.
  4. 4 Explain why DELETE /users/12 is more RESTful than GET /deleteUser?id=12.