GENDER API CSHARP

First install our library with composer:

See full client documentation here:

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

First install our library with npm:

See full client documentation here:

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

First install our library with npm:

See full client documentation here:

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

Download A Sample Project Here:

Documentation:

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
We need your consent
We use cookies (including third-party cookies) to collect information about visitors' use of our website. These cookies help us to provide you with the best possible online experience and to constantly improve our websites. Information collected via cookies may also be processed outside the European Union, for example, in the USA. By clicking the "Accept All" button, you agree to the use of cookies. To withdraw your consent at any time, change your settings or for more information about the use of cookies, click here or "Cookie Settings" at the end of the page.