Which Response default in a Rest api when partially executing an action?

Asked

Viewed 153 times

2

#define API http://localhost:80/api/v1/resources. When making a POST in resources, the user(dev) can register/include an N number of Resources. Suppose some (ones) record could not be entered, but the rest was successful. How could Response be? What status? 200 ok, 201, other? Which pattern should follow?

1 answer

4


In similar situations I use the following standard:

  • 200: OK
    No error found.

  • 202: Accepted
    Successful sending payload. is not considered an error status; return a payload containing individual successful or error descriptors.

  • 40*: Bad Request / Unauthorized / Forbidden / Not Found / etc.
    Validation errors.

  • 500: Internal Server Error
    The application launched an exception.

  • Optional - 207: Multi-Status (Webdav)
    If your client supports Webdav or XML, respond with a multi-status payload, indicating the results of each operation. RFC defining 207/Multi-status establishes XML as the desired format, which can prevent its implementation in REST/Json-based clients.

  • Maybe like this: http://pastebin.com/h1yeCq7w

  • @Danielvieirajunior Yes, this pattern would meet. If you wish you can even include a collection with the properly executed records (depending on your needs.)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.