Created
December 14, 2020 09:27
-
-
Save bethkrish/21efeab79ef50813754c709509a7945f to your computer and use it in GitHub Desktop.
Example API Client in JAVA - Standalone Application
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
package io.learn.apiclient; | |
import java.io.IOException; | |
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
import java.net.http.HttpResponse.BodyHandlers; | |
public class APIConsumer { | |
public static void main(String[] args) throws IOException, InterruptedException { | |
HttpClient httpClient = HttpClient.newBuilder().build(); | |
HttpRequest httpRequest = HttpRequest.newBuilder(URI.create("https://reqres.in/api/users?page=2")).build(); | |
HttpResponse<String> response = httpClient.send(httpRequest, BodyHandlers.ofString()); | |
System.out.println(response.statusCode()); | |
System.out.println(response.body()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment