Télécharge un exemple de projet ici :
Documentation:
https://github.com/microknights/Gender-API
using MicroKnights.Gender_API;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace GenderAPI
{
class Program
{
public static async Task RunTests(GenderApiClient client)
{
var responseStats = await client.GetStatistics();
if( responseStats.IsSuccess ) {
Console.WriteLine($"IsLimitReached: {responseStats.IsLimitReached}");
Console.WriteLine($"Remaning requests: {responseStats.RemaningRequests}");
const string Name = "Frank Nielsen";
var responseName = await client.GetByNameAndCountry2Alpha(Name, "DK");
if( responseName.IsSuccess ) {
Console.WriteLine($"{Name} is {responseName.GenderType.DisplayName}");
}
else {
Console.WriteLine($"ERRORS: {responseName.ErrorCode}-{responseName.Exception.Message}");
}
}
else {
Console.WriteLine($"ERRORS: {responseStats.ErrorCode}-{responseStats.Exception.Message}");
}
}
public static Task UsingServiceProvider(string apiKey){
var serviceProvider = new ServiceCollection()
.UseGenderAPI(apiKey)
.BuildServiceProvider();
return RunTests(serviceProvider.GetRequiredService<GenderApiClient>());
}
public static Task PlainConsole(string apiKey){
var client = new GenderApiClient(
new HttpClient
{
BaseAddress = new Uri("https://gender-api.com")
},
new GenderApiConfiguration
{
ApiKey = apiKey
});
return RunTests(client);
}
static async Task Main(string[] args)
{
var apiKey = "?";
await PlainConsole(apiKey);
await UsingServiceProvider(apiKey);
}
}
}