Venu Navat’s Post

🚀 Java’s Built-In HTTP Client — Goodbye Apache & OkHttp! 🤔 Are you still using Apache HttpClient or OkHttp for API calls in Java ? Wait… since Java 11, you don’t need them anymore 👇 Java now ships with built-in HTTP client : java.net.http.xn--HttpClient-c136i 🔥 Why It’s Awesome 🔹 No external libs, now part of JDK 🔹 Async, Non-blocking calls & HTTP/2-ready 🔹 Built-in TLS & redirects 🔹 Works great with Virtual Threads (Java 21) 💡EXAMPLE import java.net.URI; import java.net.http.*; public class JavaHttpClientDemo {    public static void main(String[] args) throws Exception {     var client = HttpClient.newHttpClient();var request = HttpRequest.newBuilder()             .uri(URI.create("https://api. github. com")).GET().build();     var response = client.send(request, HttpResponse.BodyHandlers.ofString());     System.out.println("Status: " +response.statusCode()+" Body: " +response.body()); }    } 💬 What do you think ? #Java #Java21 #VirtualThreads #HttpClient #AsyncProgramming #ModernJava

I got a bit comfy with okhttp, very easy to use and works well with retrofit Used apache http client, very powerful but not as easy as okhttp.

To view or add a comment, sign in

Explore content categories