There's an endpoint that performs file upload for upto 5 csv files. The request fails when a user hits the endpoint without sending any file. A user can send just one file or multiple files but not more than five. What appropriate response should the server give for a situation where the user uploads three files where two are csv files and one a txt file? Would the server return a 200 or 400 status code and a message stating the files that were successfully uploaded and those not successful. Or would it be more appropriate to return a 400 status code and reject all uploaded files since at least one file wasn't in the right format?
I've considered returning a 200 status code and a message stating the successfully uploaded files while stating the reason other files were not uploaded. I also return 400 status code if none of the uploaded files are in the right format. What do you guys reckon?
The response MAY be used in success, partial success and also in failure situations.
It depends on the use case and the UX you would like to provide to.
Would the server return a 200 or 400 status code and a message stating the files that were successfully uploaded and those not successful...
Consider using the MULTI-STATUS 207
HTTP code.
Here's what httpstatuses.com has to say about it:
A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate.
If you go this route, then it's perfectly fine to return 207 response and a list of details inside the response body.
This approach is a bit more involved than the alternative below, but I believe it would provide a better UX for users who upload files through HTML forms.
...would it be more appropriate to return a 400 status code and reject all uploaded files since at least one file wasn't in the right format?
This one is simpler to implement. Such approach may be preferable when it is automated system that will send the files to you web server.