Skip to content

Instantly share code, notes, and snippets.

@bethkrish
Created December 14, 2020 06:11
Show Gist options
  • Save bethkrish/64831126c3713f32fdb3149bbd47691a to your computer and use it in GitHub Desktop.
Save bethkrish/64831126c3713f32fdb3149bbd47691a to your computer and use it in GitHub Desktop.
Example API Client in C# - Console Application
using System;
using System.Net.Http;
namespace HTTPCall
{
class Program
{
static readonly HttpClient client = new HttpClient();
static async System.Threading.Tasks.Task Main(string[] args)
{
try
{
HttpResponseMessage response = await client.GetAsync("https://reqres.in/api/users?page=2");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment