froi
froi

Reputation: 7788

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?

Upvotes: 44

Views: 39641

Answers (2)

Defkon1
Defkon1

Reputation: 522

The question is a bit old, but as it is one the best result about the use of 207 Multi-status in REST API, I would suggest another scenario.

I normally use the 207 in CRUD operations that triggers some long running task, too.

E.g.: an API for an insert operation that triggers a long recalculation will reply a 207 status, with all the information about the entity inserted (201 Created + DTO) and the long running task (202 Accepted + task token). This approach fits well even when the reply should be without body (204 No content in update or delete requests).

Upvotes: 5

Sunil Kumar
Sunil Kumar

Reputation: 5657

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.

Upvotes: 60

Related Questions