Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ydinkov/Lemmy.Net
A Dependency Injected HttpClient for the Lemmy API in dotnet
https://github.com/ydinkov/Lemmy.Net
dependency-injection dotnet http-client lemmy
Last synced: about 2 months ago
JSON representation
A Dependency Injected HttpClient for the Lemmy API in dotnet
- Host: GitHub
- URL: https://github.com/ydinkov/Lemmy.Net
- Owner: ydinkov
- License: mit
- Created: 2023-06-18T10:26:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-10T20:35:11.000Z (about 1 year ago)
- Last Synced: 2024-04-27T08:03:09.516Z (5 months ago)
- Topics: dependency-injection, dotnet, http-client, lemmy
- Language: C#
- Homepage:
- Size: 483 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-lemmy - Lemmy.Net - activity/y/ydinkov/Lemmy.Net) (Projects / Libraries)
README
[![Nuget](https://img.shields.io/nuget/v/Lemmy.Net.Client)](https://www.nuget.org/packages/Lemmy.Net.Client)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/ydinkov/Lemmy.Net/nuget.yml)# A (WIP) DI http client for Lemmy in dotnet
## Usage
Run
```ps1
dotnet add package Lemmy.Net.Client
```Add this to you Startup
```cs
var services = new ServiceCollection();
services.AddLemmyClient(
new Uri(""),
"",
"",
//Optionally, add a pair of methods to read and write tokens.
//This avoid having to reauthenticate on every request
//WARNING: The file IO below is for demo purposes only!
//please use something other than files to save your tokens!
async username => File.Exists($"{username}.txt") ? File.ReadAllText($"{username}.txt") : "",
(username, jwtToken) => File.WriteAllText($"{username}.txt", jwtToken)
);
var provider = services.BuildServiceProvider();
```Then start the service
```cs
var lemmyService = provider.GetRequiredService();
```or use it in your DI consumers
```cs
using Microsoft.AspNetCore.Mvc;
using YourNamespace.Services;namespace YourNamespace.Controllers
{
public class YourController : Controller
{
private readonly ILemmyService _lemmyService;public YourController(ILemmyService lemmyService)
{
_lemmyService = lemmyService;
}// Your action methods go here
public void DoAThing(){
//Prints the names of all the communities on the instance
foreach(var c in _lemmyService.Community.List().Communities)
{
Console.WriteLine(c.Community.Name);
}
}
}
}
```## Supports
- CRUD for Communities
- CRUD for Posts (and voting)
- CRUD for Comments (and voting)
- CRUD for Private messages (and reporting)
- Site actions
- Reporting and Resolving
- Modding and Admin actions
- Captachs, registrations, password resets and email validation
- Replies, Mentions and Notifications
- Exponential retry policy## TODO
- Better querying
- Test Coverage
- Model reuse