IPWorks MQ 2020 Node.js Edition

Questions / Feedback?

SendHTTPResponse Method

Send the HTTP response.

Syntax

azurerelayreceiver.sendHTTPResponse(connectionId, statusCode, statusDescription, responseData_Buffer, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method sends an HTTP response to the HTTP request identified by ConnectionId.

The response status code and description, as well as the response body, are sent to the client using this method. The ConnectionId value should be obtained from the HTTPRequest event.

StatusCode is the three digit HTTP status code to return, for instance 200.

StatusDescription is the text corresponding to the StatusCode. For instance OK.

ResponseBody specifies the body to be sent back to the client (if any).

Code Example (HTTP)


Azurerelaylistener listener = new Azurerelaylistener();
listener.AccessKey = "9oKRDwjl0s440MlLUi4qHxDL34j1FS6K3t5TRoJ216c=";
listener.AccessKeyName = "RootManageSharedAccessKey";
listener.NamespaceAddress = "myrelay.servicebus.windows.net";
listener.HybridConnection = "hc1";

listener.OnHTTPRequest += (s, e) => {
  Console.WriteLine("HTTP Request from " + e.RemoteAddress + ":" + e.RemotePort);
  Console.WriteLine("HTTP Method: " + e.RequestMethod);
  Console.WriteLine("HTTP Request: " + e.RequestData);
  myConnectionId = e.ConnectionId;
};

//Send a response using the ConnectionId value from the HTTPRequest event
listener.SendHTTPResponse(myConnectionId, 200, "OK", myResponseBody);

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 Node.js Edition - Version 20.0 [Build 8155]