HttpClient
noun
say it: “AYCH-TEE-TEE-PEE KLY-ent” /ˌeɪtʃ tiː tiː ˈpiː ˈklaɪənt/
The .NET class that sends HTTP requests from C# code and returns the responses.
What is HttpClient in C#?
HttpClient — The .NET class your C# code uses to call a web API: it sends GET, POST, PUT and DELETE requests and gives back the responses. Create one and reuse it, rather than one per request.
HttpClient client = new() { BaseAddress = new Uri("http://localhost:5000/") };
List<Product>? products = await client.GetFromJsonAsync<List<Product>>("api/products");
Console.WriteLine(products?.Count);
In a sentence
- “Our console app uses HttpClient to read products from the API.”
Level: Journeyman · More C# terms at this level
Updated