Yes, it is possible to use the httpClient without calling waitForComplete() .
You might want to do this to avoid introducing latency in the proxy request or response flow. The HTTP request will actually complete, but the proxy flow will not wait for it.
For example, suppose you are sending a log message out to a log aggregation service, over HTTP. It might require 100ms in round-trip time to send that log message. Rather than forcing your API Proxy to wait for that log message to complete, before returning a response to the client, you can just omit the waitForComplete(), and respond “right now” to the client.
Example working JS code:
// log-To-Stackdriver.js
// ------------------------------------------------------------------
//
// Send a POST to stackdriver without waiting for a response.
//
// created: Wed Feb 15 16:28:55 2017
// last saved: <2017-February-15 18:43:10>
var variableNameRe = "[^ \t\n\"',/\\\\]+?"; // non-greedy capture
var varPrefixRe = '{';
var varSuffixRe = '}';
var variableRegex = new RegExp( varPrefixRe + '(' + variableNameRe + ')' + varSuffixRe, 'g');
function fillTemplate(template) {
// substitute all names surrounded by {curly_braces} in the template
// with the value of the corresponding context variables
var match;
while ((match = variableRegex.exec(template)) !== null) {
var variableName = match[1];
var value = context.getVariable(variableName);
if (value && value !== '') {
template = template.replace('{' + variableName + '}', value);
}
else {
template = template.replace('{' + variableName + '}', 'n/a');
}
}
return template + ''; // coerce to JS String
}
// fire and forget
var payload = fillTemplate(properties.payload);
var headers = {
'Content-Type' : 'application/json',
'Authorization' : fillTemplate(properties.authz_header)
};
var url = fillTemplate(properties.endpoint);
var req = new Request(url, 'POST', headers, payload);
var exchange = httpClient.send(req);
Companion Policy configuration:
<Javascript name='JS-Log-To-Stackdriver' timeLimit='400'>
<Properties>
<Property name='authz_header'>Bearer {stackdriver.token}</Property>
<Property name='payload'>{
"logName": "projects/{stackdriver.projectid}/logs/{stackdriver.logid}",
"resource" : {
"type": "api",
"labels": {}
},
"labels": {
"flavor": "test"
},
"entries": [{
"severity" : "INFO",
"textPayload" : "{stackdriver.logpayload}"
}
],
"partialSuccess": true
}</Property>
<Property name='endpoint'>https://logging.googleapis.com/v2/entries:write</Property>
</Properties>
<ResourceURL>jsc://log-To-Stackdriver.js</ResourceURL>
</Javascript>
Doing it this way means your API proxy logic will not be able to catch errors if the log aggregation service begins rejecting requests. Therefore you should use this “fire and forget” pattern if and only if you have some other way to ensure that your messages are flowing through to the external system. For example, some after-the-fact correlation of log messages or transaction IDs. Or even a gross count of transactions.