Вопрос

I am designing a RESTful API and am using the usual HTTP status codes like 200, 404, 500, etc.

Given the situation where occasionally the API will require additional data. When this event arises it needs to respond with a relevant status code so that the client application can present the relevant user interface.

Example:

  1. User fills in form and hits submit (using AJAX)
  2. Server sends response with some status code to indicate that further information is required which is accompanied with additional user interface.
  3. Additional user interface is displayed
  4. User resubmits form

I have this working with a 200 status code, but I would prefer to use a different status code so that my AJAX handler can detect and handle this scenario automatically.

Are there any relevant status codes or would I need to use a sub status code which is returned as a part of my JSON response?

Это было полезно?

Решение

I would go with a 400 Bad Request, since there is more data needed.

Alternatively, a 100 Continue could also work.

Either of those codes indicates that more info is needed.

Другие советы

how about 202 Accepted

"The request has been accepted for processing, but the processing has not been completed"

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

I would suggest 412 Precondition Failed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top