Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are applicable scenarios in using HTTP status 207 in REST API?

Planning to use http status 207/ multi status as a response for updating/deleting list of objects in a REST api. I plan to respond with 204 if all succeeds and 207 if it's a mixture of successes/failures.

Is this the right usage for 207?

What scenarios does http 207 commonly used on?

like image 689
froi Avatar asked Jun 01 '15 10:06

froi


People also ask

What is a 207 HTTP response?

The 207 HTTP status code means that the request is a multi-status response that includes information on a variety of resources. It is followed by an XML message containing individual response codes.

When should I use 200 or 204 status code?

The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. While 200 OK being a valid and the most common answer, returning a 204 No Content could make sense as there is absolutely nothing to return.

Which HTTP status code is returned after a successful REST API request?

2xx Status Codes [Success] Indicates that the request has succeeded. Indicates that the request has succeeded and a new resource has been created as a result. Indicates that the request has been received but not completed yet.


1 Answers

If you perform a destructive operation like POST, PUT, DELETE against more than one resource and the operations against each individual resource did not share a common outcome then you can go for 207.

For example,

  • If you DELETEd two resources and both were deleted you can expect
  • If both DELETEs were forbidden, you'd expect 403.
  • If one DELETE was successful but one was forbidden, you would receive 207.

Some more discussion on 207 status.

like image 61
Sunil Kumar Avatar answered Sep 26 '22 08:09

Sunil Kumar