REST call - Is it possible to set the response StatusCode from the application?

0
Hi, My customer asks me to set the StatusCode of REST call to 413 in a certain case. 413 meaning the response is too large. I did not find how to do something like that from the application. Does anybody if that is possible? Thanks! Toon ps. Below a snippet from the W3C definitions of StatusCodes and the Mx documentation on the HttpResponse.     === Update August 16th === The replies make clear that the response code can be updated, I’m afraid I still need a bit more help in understanding how :-) The part I do not understand is the mentioned parameter. Where do I add this parameter? And how does the MF return the objects or the HttpResponse object Here is the definition of the REST call:  
asked
6 answers
5

Use HttpResponse (system module ) as the final return of your microflow.

Maybe the image bellow helps you a little on how to do that.

answered
3

Did you look at the non persistent object  HttpResponse in the system module? Give your webservice call microflow that object as parameter and change it to the right StatusCode.

Regards,

Ronald

 

answered
1

Here are the steps:

  1. Create a microflow that takes two parameters
    1. System.HttpRequest
    2. System.HttpResponse
  2. Publish that microflow as a REST operation
  3. Add a decision to the microflow that checks the size of the HttpRequest
    1. In the flow where it’s ok, handle the request normally, and set HttpRequest/StatusCode and HttpRequest/Content, and maybe create some response headers, just as you normally would.
    2. In the flow where it’s not ok, set HttpRequest/StatusCode to 413
answered
1

In your microflow that handles the REST call, create a system.httpresponse object. You can now validate some things, and depending on whether or not the call is succesful (which would be a 200 response), you can change the StatusCode attribute. So in your case, put 413 where the arrow is. 

 

Then, return your httpResponse:

If all goes well, it should be visible here in your published rest service operation:

 

answered
1

Here is how I now implemented it (as a test):

Now I do get back the 413 nicely. Thanks for the help!

answered
1

I made a response for you, but I saw it’s done by you ;-).

Extra notes:
 

  • ’False’ is not very description in your decision
  • Status code 413 means that the payload is too large. Payload is part of the request. So you need to check and return this status code in a very early stadium!
  • And why do you need status code 413? Why this requirement?
answered