Advanced API Topics

Now that we have learned the basics of creating a RESTful Web API we will discuss advanced some API programming techniques.

Updated

Dissecting the Request and Response

  1. The Request / Response Pattern (Journeyman): A web request and its response are simple text messages, each made of a header and an optional body.
  2. Using a Simple HTTP Client (Journeyman): Test an API without leaving your editor by writing requests in a .http file and running them from IntelliJ or VS Code.

Returning HTTP Status Codes

  1. Returning HTTP Status Codes: an overview (Apprentice): Why the default status codes (200 on success, 500 on any error) aren't enough, shown by a request for a category that doesn't exist and still gets 200.
  2. Common HTTP Status Codes (Apprentice): The status codes a REST API uses most, 200, 201, 204, 400, 401, 403, 404 and 500, and what each tells the client.
  3. Returning ResponseEntity<T> (Journeyman): Return a ResponseEntity from a controller method to choose the status code, for example 404 when a category isn't found and 500 when something fails.

Handling Global Exceptions

  1. Handling Global Exceptions (Freelancer): Use a @RestControllerAdvice class with an @ExceptionHandler to send every error back in one format, 404 for a path that doesn't exist and 500 for anything else.