C# Tutorial: HTTP Basics
Make HTTP requests with HttpClient, parse JSON responses, and handle HTTP errors.
HTTP and the web
`HttpClient` is the modern .NET way to make HTTP requests. Combine it with `async/await` for non-blocking network calls.
`System.Text.Json` is the built-in JSON serialiser — fast, lightweight, and part of the standard library.
What you'll learn in this C# http basics tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 20 minutes.
- Create and configure HttpClient — Create an HttpClient and set headers.
- GET a string — `GetStringAsync` fetches a URL and returns the body as a string.
- Check status code — `GetAsync` gives you the full response including status code.
- Deserialise JSON — Use `JsonSerializer.Deserialize<T>` to parse JSON into a C# object.
- Serialise to JSON — `JsonSerializer.Serialize<T>` converts an object to JSON.
- POST with JSON body — Send a POST request with a JSON body.
- Error handling — Handle HTTP errors gracefully.
- Query parameters and headers — Build URLs with query strings and add headers.
C# HTTP Basics concepts covered
- HTTP and the web