Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What status code should I return when part of a bulk update fails?

Tags:

rest

http

web

Let's say I'm a server responding to a request to do a bulk create of some entity. Let's say that I've also decided to make it so that if one instance of the entity can't be created, due to a server error or user error, I will still create the other entity instances. In this scenario what should I return? A 201 because I created most of the entities in the request? Or A 4xx/5xx since there was an error while creating one of the entities?

like image 771
David Avatar asked Oct 15 '25 15:10

David


1 Answers

If you return a 4xx code it implies that the entire request has failed, and the server-state has not changed.

If the intent of the request is to do 'one or more things and some may fail', then a partial application is still a success, so that puts in the 2XX range.

206 is not a good idea. This is specifically for requests that use Range, which is not the case here.

207 could be used. You'll probably want to define a custom format instead of the default XML-based on. My vote would probably just go to 200.

Also, consider just doing many requests. Requests are cheap, why lump them together? Now each request can have their own beautiful, accurate status code.

like image 74
Evert Avatar answered Oct 17 '25 09:10

Evert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!