SylveonDeko / Nekos.Best-API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nekos.Best API Wrapper

nuget version downloads

https://docs.nekos.best/index.html

Overview

Nekos.Best API is a RESTful API serving fully SFW and high quality anime images and GIFs.

We focus on giving the best experience for our users and their projects, for free.

If you find any errors/issues or want any features added, create an issue

Getting started

Installing the package

Add the NuGet package NekosBestApiNet to your project:

dotnet add package NekosBestApiNet

Simple usage

using System;
using System.Threading.Tasks;
using NekosBestApiNet;

public class ExampleClass
{
  private readonly NekosBestApi _nekosBestApi;

  public ExampleClass() 
    => _nekosBestApi = new NekosBestApi();

  public async Task Hug() 
  {
    var image = await _nekosBestApi.ActionApi.Hug();

    Console.WriteLine(image.Results.FirstOrDefault().Url);
  }
}

Example using custom HttpClient

You can provide your own HttpClient instance, but you have to set the BaseAddress manually

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using NekosBestApiNet;

public ExampleClass() 
{
  var httpClient = new HttpClient 
  {
    BaseAddress = new Uri("https://nekos.best/api/v2")
  };

  _nekosBestApi = new NekosBestApi(httpClient);
}

Example using dependency injection

Create a ServiceCollection, then add an instance of the NekosBestApi class to it

using System;
using System.Threading.Tasks;
using NekosBestApi;
using Microsoft.Extensions.DependencyInjection;

public class Startup 
{
  private NekosBestApi _nekosBestApi;

  private IServiceProvider _serviceProvider;

  public void Init() 
  {
    var services = new ServiceCollection();

    _nekosBestApi = new NekosBestApi();

    ConfigureServices(services);
    _serviceProvider = services.BuildServiceProvider();
  }

  public async Task RunAsync() 
  {
    var exampleClass = _serviceProvider.GetService<ExampleClass>();

    var image = await _nekosBestApi.ActionApi.Hug();

    Console.WriteLine(image.Results.FirstOrDefault().Url);
  }

  private void ConfigureServices(IServiceCollection services) 
  {
    services.AddSingleton(_nekosBestApi);
    services.AddSingleton<ExampleClass>();
  }
}

Using this in a class:

using System.Threading.Tasks;
using NekosBestApi;
using NekosBestApi.Models.Images;

public class ExampleClass 
{
  private readonly NekosBestApi _nekosBestApi;

  public ExampleClass(NekosBestApi nekosBestApi) 
    => _nekosBestApi = nekosBestApi;

  public async Task<ActionResult> Hug()
    => await _nekosBestApi.Hug();
}

About

License:MIT License


Languages

Language:C# 100.0%