Hello,
I am creating api proxy program where I can send bunch of POST request and GET request. With those request I have to send JSON body with bunch of key-values pairs and in return I get JSON response where also key-values pair comes .
Please guide me If there is and build in policy is there or how do I do in JavaScript policy.
Please share sample code or example for understand format.
Thank you.
Solved! Go to Solution.
Here is a sample that posts an entry to Splunk using an async POST method.
var splunkLoggingServerURL = context.getVariable("logConfig.splunkLoggingServerURL"); var splunkLoggingServerBasicAuth = context.getVariable("logConfig.splunkLoggingServerBasicAuth"); var logJsonObj = JSON.parse(context.getVariable("log")); logJsonObj.foo = "bar"; var headers = { 'Content-Type': 'application/json', 'Authorization': splunkLoggingServerBasicAuth }; var myRequest = new Request(splunkLoggingServerURL, "POST", headers, JSON.stringify(logJsonObj)); // asynchronous POST for performance reasons httpClient.send(myRequest);
The sample gets a log message from context, parses it out, adds additional attributes, stringifies the modified object, then performs the POST.