Stage 6 · Lesson 4 of 8
Calling a public API with HttpClient
sends HTTP requests. Create one instance and reuse it for the life of the program, because creating one per request can use up the computer's network (connection slots). await client.GetAsync(url) returns a response for any .
So check response.IsSuccessStatusCode, or call EnsureSuccessStatusCode(), before the body. Then parse it with await response.Content.ReadFromJsonAsync<Weather>(). 401 means a bad key, 404 a wrong URL and 429 too many requests.
Set client.Timeout so a slow server cannot hang your app, and catch HttpRequestException for network failures. Every call is , so await it all the way up. Wrap the calls in one class that returns your own records.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with
- GitHub repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch