Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 2.31 KB

NREADME.md

File metadata and controls

55 lines (44 loc) · 2.31 KB

PartyDotNet

A .NET client for the Party API made with Refit.

version NuGet Version Contributors Issues

Installation

The latest release can be download from NuGet or from the GitHub packages and releases pages.

Usage

Without a session cookie

IPartyClient apiClient = RestService.For<IPartyClient>("https://kemono.su/api/v1");
List<Post> posts = await apiClient.GetRecentPosts();

With a session cookie

CookieContainer container = new();
container.Add(new Cookie("session", "<session cookie>", string.Empty, "coomer.su"));

HttpClientHandler handler = new() { CookieContainer = container };
HttpClient httpClient = new(handler) { BaseAddress = new Uri("https://coomer.su/api/v1") };

IPartyClient apiClient = RestService.For<IPartyClient>(httpClient);
List<FavoriteCreator> creators = await apiClient.GetFavoriteCreators();

With IHttpClientFactory

Configuring services

ServiceCollection collection = new();

CookieContainer container = new();
container.Add(new Cookie("session", "<session token>", string.Empty, "kemono.su"));

collection.AddHttpClient("KemonoClient", client =>
{
    client.BaseAddress = new Uri("https://kemono.su/api/v1");
})
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
    CookieContainer = container
});

_serviceProvider = collection.BuildServiceProvider();

Getting a client from IHttpClientFactory

IPartyClient apiClient = _serviceProvider.GetRequiredService<IHttpClientFactory>().CreatePartyClient("KemonoClient");
HttpResponseMessage response = await apiClient.AddFavoriteCreator(Service.Patreon, "2448989");