GENDER API CSHARP

Installier zuerst unsere Library mit Composer:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client

Installier zuerst unsere Library mit npm:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client-npm

Installier zuerst unsere Library mit npm:

Link zur Client-Dokumentation auf Github:

https://github.com/markus-perl/gender-api-client-npm

Beispielprojekte hier herunterladen:

Dokumentation:

https://github.com/microknights/Gender-API
// Contributed Client: 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){
            // client is thread-safe, and can be used static.
            var serviceProvider = new ServiceCollection()
                .UseGenderAPI(apiKey)
                .BuildServiceProvider();

            return RunTests(serviceProvider.GetRequiredService<GenderApiClient>());
        }

        public static Task PlainConsole(string apiKey){
            // client is thread-safe, and can be used static.
            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);
        }
    }
}
Chat