I am looking at this OData spec and trying to follow - Asynchronous Requests.
As per the spec, when client polls for status using “location-header” then:
1. Success case Spec says “A GET request to the status monitor resource returns 200 OK once the asynchronous processing has completed. This response MUST include a Content-Type header with value application/http as described in [RFC7230]. The response body MUST enclose a single HTTP response which is the response to the initial Data Service Request.”
Question_1: So, my understanding is the response body should return the API response parameters like below. Is my understanding correct?
Response
HTTP/1.1 OK
OData-Version: 4.0
Content-Type: application/http
{
"Property1": "foo",
"Property2": "bar"
}
Question_2: Follow up for above #1: In Location Header API response, can we put:
- Any other useful additional params
- the initial API response params can be put in different format (nested object)?
Example:
- there are 10 apis and each one returns different response params ex: api1, api2, api3
- Now when these 10 apis are invoked asynchronously .. then we return location-header pointing to common API Ex: LocationHeaderAPI(trackingId) which returns LocationHeaderResponse
- When client polls on this LocationHeaderAPI … since LocationHeaderResponse has its own fixed response params we cannot return the api1, api2, api3 response in same format. This locationHeaderAPI can return something like:
locationHeaderResponse for API_1
{
“ApiResponse” :
{
“api1_param1”: “value”,
“api1_param2”: “value”
},
“additional useful param”: “value”
}
locationHeaderResponse for API_2
{
“ApiResponse” :
{
“api2_param1”: “value”,
“api2_param2”: “value”
},
“additional useful param”: “value”
}
2. Failure case Spec says “If an asynchronous request is cancelled for reasons other than the consumers issuing a DELETE request against the status monitor resource, a GET request to the status monitor resource returns 200 OK with a response body containing a single HTTP response with a status code in the 5xx Server Error range indicating that the operation was cancelled.”
Question_3: In this case, action failed during execution bcoz of some error. So question is what is the expected response payload? Is there any standard here (or) can we send any payload telling the status ?
Example:
Response
HTTP/1.1 OK
OData-Version: 4.0
Content-Type: application/http
{
“http status”: 5xx,
“status”: “failed”,
“error code”: 0x1234,
“message”: “xyz error text message”,
“some other param”: “some other text”
}