Refit is a library heavily inspired by Square’s Retrofit library, and it turns your REST API into a live interface:
public interface IGitHubApi
{
[ ]
Task<User> GetUser(string user);
}
The RestService class generates an implementation of IGitHubApi that uses HttpClient to make its calls:
var gitHubApi = RestService.For<IGitHubApi>("https://api.github.com");
var octocat = await gitHubApi.GetUser("octocat");
.NET Core supports registering via HttpClientFactory
services
.AddRefitClient<IGitHubApi>()
.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://api.github.com"));