What is a good way to return a partial success res

2019-06-25 08:18发布

This question already has an answer here:

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.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-06-25 09:01

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

查看更多
登录 后发表回答