How do you call an API from C#?
- To call an API for data, we can use the built-in HttpClient that comes with the System.Net namespace.
using (HttpClient client = new HttpClient())
var response = await client.GetStringAsync("http://referbruv.com");
- HttpClient implements the IDisposable interface and so can be used under a using block. But it is one of those unmanaged resources which should not be released frequently and instead be reused as much as possible.
Posted May 14, 2021