Slide 12
Slide 12 text
public class Main {
public static void main(String [] args) {
try {
String data = makeHttpRequest("https://jsonplaceholder.typicode.com/todos/");
System.out.println(data);
} catch(URISyntaxException | IOException | InterruptedException e) {
e.printStackTrace();
}
}
public static String makeHttpRequest(String url)
throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(url))
.build();
HttpResponse response = client.send(request,
HttpResponse.BodyHandlers.ofString());
return response.body();
}
}
Uses HttpClient to
make http request