Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to return a partial success response for a REST API? [duplicate]

I am working on a use case where I have a dependency on a downstream API. The issue is that a single resource for me is made up of multiple resources for the downstream service. So a single write to my API may be internally multiple calls to the external service and any one of those calls may fail.

In the case of everything being good I am returning a 200 OK empty response and in the case of an invalid request or server error I am returning a separate error response. What should I return in the case of partial success? I am aware of the 207 Multi-status response code but am not sure if that is applicable here since that looks like it's more applicable to a batch operation. A 207 response with a list of failed sub entities looks like the best bet as of now. Any ideas of a more cleaner way would be appreciated.

like image 519
Chakkakuru Avatar asked Oct 31 '22 03:10

Chakkakuru


1 Answers

This was more sort of a design choice so finally I went with the following response model 1. Success - 200 OK with applicable body 2. Partial success - 200 OK with applicable body plus warnings 3. Failure(4xx/5xx) - errors body listing the errors

like image 102
Chakkakuru Avatar answered Nov 04 '22 12:11

Chakkakuru