Skip to content

FawazTakahji/PartyDotNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


PartyDotNet

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

Report Bug . Request Feature

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");