Author |
Message
|
urufberg |
Posted: Sun Aug 18, 2019 7:30 pm Post subject: StatusCode not changing in REST API |
|
|
Apprentice
Joined: 08 Sep 2017 Posts: 28
|
Hi,
I'm developing an API POST method using a mapping node. My problem is that when I try to override the REST>Response>StatusCode in the Local Environment, this code is not passed in the response and instead I get a 200 OK as a response in Postman.
The code I'm passing is defined in the swagger, so If I understand correctly, it should take the StatusCode I'm setting so, what am I missing?
For context:
IIB v10 fix 17
Thanks in advance! |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Aug 19, 2019 4:28 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
AFAIK there is no environmental override for the status code. It needs to be set on the HTTP Header...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
abhi_thri |
Posted: Mon Aug 19, 2019 4:42 am Post subject: |
|
|
 Knight
Joined: 17 Jul 2017 Posts: 516 Location: UK
|
|
Back to top |
|
 |
urufberg |
Posted: Mon Aug 19, 2019 6:11 am Post subject: |
|
|
Apprentice
Joined: 08 Sep 2017 Posts: 28
|
Thank you for your responses @fjb_saper and @abhi_thri.
abhi_thri wrote: |
as mentioned in the previous post the Statuscode cannot be overridden as that is something returned in the response and not in the request. |
I'm failing to understand then why you can define the REST API responses and statuts code (is it just for documentation?).
abhi_thri wrote: |
https://www.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/bz90950_.htm |
In this document, the following Local Environment variable is defined:
Quote: |
LocalEnvironment.WrittenDestination.REST.StatusCode integer: The HTTP status code in the response from the REST API. |
What i'm looking for is to return an standard error code if certain conditions are met.
Maybe a more general question would be, how do you guys usually go about implementing error responses in your IIB REST APIs?
Thank you, |
|
Back to top |
|
 |
abhi_thri |
Posted: Mon Aug 19, 2019 7:34 am Post subject: |
|
|
 Knight
Joined: 17 Jul 2017 Posts: 516 Location: UK
|
urufberg wrote: |
I'm failing to understand then why you can define the REST API responses and statuts code (is it just for documentation?).
In this document, the following Local Environment variable is defined:
Quote: |
LocalEnvironment.WrittenDestination.REST.StatusCode integer: The HTTP status code in the response from the REST API. |
|
hi...anything that comes at "WrittenDestination" cannot be overridden, it is just available for inspection. i.e you can only override the Request parms and not the results returned from the Web call which are logged at "WrittenDestination". You can indeed inspect these values and then decide on how to progress further |
|
Back to top |
|
 |
timber |
Posted: Mon Aug 19, 2019 7:43 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Should be possible to specify the HTTP status code that your message flow sends: https://www.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ac20450_.htm
Quote: |
Setting the HTTP Status Code for a reply
The default HTTP Status Code is 200, which indicates success. If you want a different status code to be returned, take one of the following actions:
* Set your status code in the field Destination.HTTP.ReplyStatusCode in the local environment tree (correlation name OutputLocalEnvironment). This field overrides any status code that is set in an HTTPResponseHeader header. This action is the preferred option, because it provides the greatest flexibility.
* Set your status code in the field X-Original-HTTP-Status-Code in the HTTPReplyHeader header.
* Set your status code in the field X-Original-HTTP-Status-Code in the HTTPResponseHeader header. This option is useful if you include an HTTPRequest node before the HTTPReply node in your flow, because the HTTPResponseHeader header is created for you. In this scenario, an HTTPResponseHeader header has been created in the logical tree, representing the HTTP headers in the response from another web service. If you have selected the Generate default HTTP headers from reply or response property on the HTTPReply node, values for the response header are set as default values when the reply message is created. |
|
|
Back to top |
|
 |
urufberg |
Posted: Mon Aug 19, 2019 8:37 am Post subject: |
|
|
Apprentice
Joined: 08 Sep 2017 Posts: 28
|
abhi_thri wrote: |
hi...anything that comes at "WrittenDestination" cannot be overridden, it is just available for inspection. i.e you can only override the Request parms and not the results returned from the Web call which are logged at "WrittenDestination". You can indeed inspect these values and then decide on how to progress further |
Thank you. Im guessing that the LocalEnvironment>REST>Response>StatusCode parameter is also intended to be inspected and not changed based on timbers response
timber wrote: |
Should be possible to specify the HTTP status code that your message flow sends: https://www.ibm.com/support/knowledgecenter/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ac20450_.htm
Quote: |
Setting the HTTP Status Code for a reply
The default HTTP Status Code is 200, which indicates success. If you want a different status code to be returned, take one of the following actions:
* Set your status code in the field Destination.HTTP.ReplyStatusCode in the local environment tree (correlation name OutputLocalEnvironment). This field overrides any status code that is set in an HTTPResponseHeader header. This action is the preferred option, because it provides the greatest flexibility.
* Set your status code in the field X-Original-HTTP-Status-Code in the HTTPReplyHeader header.
* Set your status code in the field X-Original-HTTP-Status-Code in the HTTPResponseHeader header. This option is useful if you include an HTTPRequest node before the HTTPReply node in your flow, because the HTTPResponseHeader header is created for you. In this scenario, an HTTPResponseHeader header has been created in the logical tree, representing the HTTP headers in the response from another web service. If you have selected the Generate default HTTP headers from reply or response property on the HTTPReply node, values for the response header are set as default values when the reply message is created. |
|
Thanks! I don't know why I have the idea that there was a specific functionality built int for REST flows.
I still wonder:
fbergeret wrote: |
how do you guys usually go about implementing error responses in your IIB REST APIs? |
Regards |
|
Back to top |
|
 |
|