java.net.http.HttpClient is in the JDK since Java 11. GET and POST below need no Apache, RESTEasy, or OkHttp dependency.

HttpClient client = HttpClient.newHttpClient();

HttpRequest getRequest = HttpRequest.newBuilder()
        .uri(URI.create("https://example.com/users/1"))
        .GET()
        .build();
HttpResponse<String> getResponse = client.send(getRequest, HttpResponse.BodyHandlers.ofString());

HttpRequest postRequest = HttpRequest.newBuilder()
        .uri(URI.create("https://example.com/users"))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString("{\"name\":\"Ada\"}"))
        .build();
HttpResponse<String> postResponse = client.send(postRequest, HttpResponse.BodyHandlers.ofString());

getResponse.statusCode() is the HTTP status. getResponse.body() is the response body as a String. URI, HttpClient, HttpRequest, and HttpResponse are in java.net and java.net.http.

The same calls with a third-party client:


You may also find these posts interesting: