I need to get data from an ApiGateway api method. My API is deployed and url is like /greetings. "greetings" is my resource name in which I have a GET method with Authentication set to aws_iam.
The method returns a json response which i want to simply fetch and return. Before authenticating below code was enough to get the response:
String url = "XXXX/greetings"; // xxxx is replaced by api url
URL obj = new URL(url);
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print response
Note: I understand that I have to pass Authentication token with the request and I am able to access the authenticated API url with Postman by using my AWS credentials. My query is how do I do this in Java?