Medium.Client
1.1.0
dotnet add package Medium.Client --version 1.1.0
NuGet\Install-Package Medium.Client -Version 1.1.0
<PackageReference Include="Medium.Client" Version="1.1.0" />
paket add Medium.Client --version 1.1.0
#r "nuget: Medium.Client, 1.1.0"
// Install Medium.Client as a Cake Addin #addin nuget:?package=Medium.Client&version=1.1.0 // Install Medium.Client as a Cake Tool #tool nuget:?package=Medium.Client&version=1.1.0
Unofficial Medium API .NET SDK
This SDK was developed based on Unofficial Medium API.
Installation
Install the package from NuGet.org Medium.Client.
Assumptions
You need to have a Rapid API account and subscribe to the Medium API. Follow the steps from the official documentation here.
Configuration
After installing the NuGet package in your project you just need to use the following extension method to add the medium client interfaces to your service collection.
services.AddMediumClient();
Once you have the API Key from Rapid API, you just need to add it in the following variable in your settings file or as an environment variable.
{
"Medium": {
"ApiKey": "your-key"
}
}
Supported API endpoints
All the existing endpoints are supported by this SDK. There are some additional features to simplify the API calls. For example, the API provides an endpoint to get the user info based on the user identifier. This SDK has an additional method to get this info but is based on a username. This avoids having 2 method calls. However, in reality, the SDK will make that 2 API calls.
// 2 method calls
var userId = await _mediumClient.Users.GetIdByUsernameAsync("username");
var userInfo = await _mediumClient.Users.GetInfoByIdAsync(userId);
// 1 method call
var userInfo2 = await _mediumClient.Users.GetInfoByUsernameAsync("username");
How to use it?
In your class, you have 2 options to use the Medium client functionalities.
- Option 1 (using the main IMediumClient interface)
public class MyService
{
private readonly IMediumClient _mediumClient;
public Worker(IMediumClient mediumClient)
{
_mediumClient = mediumClient;
}
public async Task ExecuteAsync()
{
var user = await _mediumClient.Users.GetListsByUserIdAsync("user-id");
var article = await _mediumClient.Articles.GetResponsesAsync("article-id");
}
}
- Option 2 (using the specific interface)
public class MyService
{
private readonly IUserClient _userClient;
public Worker(IUserClient userClient)
{
_userClient = userClient;
}
public async Task ExecuteAsync()
{
var user = await _userClient.GetListsByUserIdAsync("user-id");
}
}
How to use the default retry policy?
services.AddMediumClient(defaultRetryPolicy: true);
Retry Policy definition: Handle transient HTTP errors and NotFound status code. There will be 5 retries with a decorrelated Jitter backoff.
How to use a custom retry policy?
services.AddMediumClient()
.WithRetryPolicy(m =>
{
// your retry logic here
});
Roadmap ✈️
- Add in memory mock client implementation to simplify the development. With this, we can try the SDK without having Rapid API access.
Give me a star if you like it ⭐
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
- System.Text.Encodings.Web (>= 8.0.0)
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Http.Polly (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Polly.Contrib.WaitAndRetry (>= 1.1.1)
- System.Text.Encodings.Web (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.