Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@c3ry5
Last active March 15, 2023 04:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save c3ry5/aed435d6d1101bc2d6ee to your computer and use it in GitHub Desktop.
Save c3ry5/aed435d6d1101bc2d6ee to your computer and use it in GitHub Desktop.
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