Skip to content

Instantly share code, notes, and snippets.

@c3ry5 c3ry5/aem.cq.getRequest.js
Last active Jun 19, 2018

Embed
What would you like to do?
Get request using the AEM sightly Javascript use api
"use strict";
use(function() {
var url = this.api,
getRequest = new org.apache.commons.httpclient.methods.GetMethod(url),
client = new org.apache.commons.httpclient.HttpClient(),
status = new org.apache.commons.httpclient.HttpStatus(),
inputStream;
console.log("Retrieving data from " + url);
try {
var statusCode = client.executeMethod(getRequest);
console.log(statusCode);
if (statusCode == status.SC_OK) {
inputStream = getRequest.getResponseBodyAsString();
console.log('Retrieved Data');
} else {
console.log('Failed to execute http method');
}
} catch (e) {
console.log(e);
} finally {
console.log('Finished');
}
return inputStream;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.