Hi Gugi,
Ok, in practice my question is as follows:
Currently when you use an HTTP transformer (or the equivalent in an incoming), you can click the ‘add headers to response body’. This adds the headers, giving you something like this:
{
"headers": {
"Date": [
"Wed, 27 Nov 2024 09:59:40 GMT"
],
"Content-Type": [
"application/json"
],
"Content-Length": [
"570"
],
"Connection": [
"keep-alive"
],
"Server": [
"gunicorn/19.9.0"
],
"Access-Control-Allow-Origin": [
"*"
],
"Access-Control-Allow-Credentials": [
"true"
]
},
"data": {
"responseFromApi": "test"
}
}
That’s useful, but what if I need to check what the actual response-status-code was? The headers don’t help me with this, since they don’t give a ‘http-status’ or anything.
So what if the same ‘Add headers to response body’ could return this?
{
"http_status": {
"status_code": "200",
"status_message": "Accepted"
},
"headers": {
"Date": [
"Wed, 27 Nov 2024 09:59:40 GMT"
],
"Content-Type": [
"application/json"
],
"Content-Length": [
"570"
],
"Connection": [
"keep-alive"
],
"Server": [
"gunicorn/19.9.0"
],
"Access-Control-Allow-Origin": [
"*"
],
"Access-Control-Allow-Credentials": [
"true"
]
},
"data": {
"responseFromApi": "test"
}
}
This would allow you to check within the following transformers if you’ve got the expected status code.
A particular example of why I’d need this is APIs which don’t (or with too limited options) allow for filtering on a list. So let’s say I’d need to check whether a product exists - normally I’d do something like /products?filter=sku eq 'ABC'
, and check the result array to see if the product exists. However, if I can’t filter, maybe I need to do this: /products/ABC
. This would return a 404 if it doesn’t. That’s not a problem, in the Client we can accept a 404. However, there’s now not a “good” option (you can do stuff like ‘key exists’, but that’s just ugly) to check the response status code.