Last active
March 15, 2023 04:39
-
-
Save c3ry5/aed435d6d1101bc2d6ee to your computer and use it in GitHub Desktop.
Get request using the AEM sightly Javascript use api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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