Hands-On RESTful Web Services with TypeScript 3
上QQ阅读APP看书,第一时间看更新

2xx – success

The variations of 2xx status codes, which represent success scenarios, can be compressed into four main 2xx status codes:

  • 200 OK: This is the most common happy path response, indicating that the request succeeded.
  • 201 Created: This indicates that a new resource has been successfully created. It is most commonly used as a response to POST request methods. This response should contain a location header, which provides the URL for the new resource that has been created. There is a recommendation to send the response body back with the newly created resource. Essentially, the response body is the same if the consumer hits the GET endpoint to retrieve the resource.
  • 202 Accepted: This is kind of equivalent to 201. The only difference is that 202 is used for asynchronous operations, as it clearly indicates eventual consistency.
  • 204 No Content: This is also similar to 200, but only when there is no response body. This is mostly used for DELETE requests.