Hi i've reading a mule 4 documentation a lot but did not find answer for this. How can i set the HTTP status in the dataweave transformer? In mule 3 it was set within the set property component. Thanks
2 Answers
2
votes
You can use the statusCode attribute in the http:response of the listener to tell it where to pickup the status from. The following example will pick it up from a var called httpStatus or default to 200 if the var is not available after flow execution:
<http:listener config-ref="api-httpListenerConfig" path="/api/v1/*">
<http:response statusCode="#[vars.httpStatus default 200]">
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:response>
<http:error-response statusCode="#[vars.httpStatus default 500]">
<http:body>#[payload]</http:body>
<http:headers>#[vars.outboundHeaders default {}]</http:headers>
</http:error-response>
</http:listener>