Junior — Middle
What tools or libraries have you used for implementing HTTP requests at your previous job?
sobes.tech AI
Answer from AI
To implement HTTP requests in C# at my previous job, I used the HttpClient class from the System.Net.Http namespace. It is a standard and convenient way to send asynchronous requests and receive responses.
Example of a simple GET request:
using System.Net.Http;
using System.Threading.Tasks;
HttpClient client = new HttpClient();
async Task<string> GetDataAsync(string url)
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
return responseBody;
}
Additionally, for more complex scenarios, I used libraries like Refit (for declarative API description) and RestSharp, which simplify working with REST APIs.