Java Tutorial: HTTP & JSON
Make HTTP requests with Java's built-in HttpClient, parse JSON responses, build REST clients, and handle async HTTP.
Connect to the world
Java 11+ ships with `java.net.http.HttpClient` — a modern, async-capable HTTP client with no external dependencies.
Combined with JSON parsing, you can build REST clients, call APIs, and integrate with any web service — all in standard Java.
What you'll learn in this Java http & json tutorial
This interactive Java tutorial has 6 hands-on exercises. Estimated time: 22 minutes.
- HttpClient basics — Java 11+ includes `java.net.http.HttpClient`. The three main classes:
- Making a GET request — `client.send(request, BodyHandlers.ofString())` makes the HTTP call:
- Simple JSON parsing — Without an external library, parse simple JSON using String operations or `org.json`.
- POST request with JSON body — Send data with a POST request:
- Async HTTP with sendAsync — `sendAsync()` returns a `CompletableFuture` — doesn't block the thread:
- Build a REST client — Final challenge — no starter code.
Java HTTP & JSON concepts covered
- Connect to the world