Error Handling & HTTP Responses

We have learned how to design an API for specific problems. API is not only about sending a response for every request. It is also about sending a standard response for the request.

API responses need to be inconsistent across the request. Only the data need to change not the whole structure of the response. Developer experience is an important metric while building an API.

Two important parts of the response are,

  • Error handling and friendly errors in the response
  • Proper HTTP status codes in the response

Let's deep dive into those in this chapter.