Responding to requests with HTTP status codes

0 votes
asked Mar 20, 2018 by (240 points)
It seems like every request made to QIE gets a response back with an HTTP status code of 200 or 500.  Is there a way to manually set the HTTP status code on responses.  For instance, if I wanted to return 400 series codes for request/auth issues.  Or if I wanted to just manually return a 500 without relying on the underlying QIE code failing.

1 Answer

+1 vote
Best answer

You can add the following options to the start of the response:

var response = "HTTP Status: 404\r\n";
response += "http.header.Content-Type=text/plain\r\n";
response += "http.header.myToken=ABCDEF\r\n";
response += "\r\n";
response += "This is my payload";


The HTTP Status can return any integer value for the status code.

The Content-Type allows you to specify the payload content type.

The http header can be any additional headers that are needed in the response.  To specify a header, you will prefix the header name with "http.header.", separate the header name (key) and the value with a colon (=), and end with a carriage return line feed (\r\n).


Make sure that you have set your source node to response to "From Mapping or Destination node"


You can create a custom mapping function withe the qie.postMessageResponse(response);


See also:

Handling HTTP requests and responses

Posting Responses via qie.postMessageResponse() in a channel that uses an HTTP Listener source node

answered Mar 20, 2018 by ben-s-7515 (12,640 points)
edited May 17 by rich-c-2789
commented Nov 17, 2021 by golden-m-1060 (120 points)
I'm using this to check an api token in the first step of my mapping function.  If the api-token isn't valid I'm posting the message response as shown above, but how can I stop processing at that point?  If I use a return statement, (at least in test mode) the rest of the mapping function executes.