Scenario:
A POST
request is sent to process an order that will result in data retrieval from an external datasource.
There are three possible results:
- The datasource returned data for the request
- No data was available for the request (this is viewed as an error)
- The datasource couldn't be accessed (may be down for maintenance)
An obvious response for 1 is 200: OK
or 201: Created
(an entity is created from this request).
What status codes would be appropriate for 2 and 3?
Status codes I have considered:
503: Service Unavailable
when datasource is down500: Internal Server Error
when datasource is down502: Bad Gateway
when "no data available"404: Not Found
when "no data available"403: Forbidden
when "no data available"412: Precondition Failed
when "no data available"
GET
isn't appropriate because these data queries are neither safe nor idempotent (they may result in the exchange of money among other things). – Ectomy2.
I would split into multiple cases. If no post data is given we should throw an400 Bad Request
. If a mandatory field is not set but other data is correct raise an412 Precondition Failed
. – Effectuate