Client library (C# wrapper) written in .NET (7.0/8.0) that provides an easy way to interact with the official Clash Royale API directly or through proxy
Stable | |
---|---|
Clash Royale API Client |
- .Net 7.0; .Net 8.0
- Dependency injection ready (can also be used standalone, see below)
- Supports async calls.
Logo | Stable | |
---|---|---|
Clash Royale API Client |
Following commands can be used to install MageCorp.ClashRoyaleApi.Client, run the following command in the Package Manager Console
NuGet\Install-Package MageCorp.ClashRoyaleApi.Client
Or use dotnet cli
dotnet add package MageCorp.ClashRoyaleApi.Client
If you do not want to use any DI framework, you have to instantiate ClashRoyaleApiClient
as follows.
ApiOptions apiOptions = new("<your token>");
var clashRoyaleApiClient = ClashRoyaleApiClient.Create(apiOptions);
var playersService = clashRoyaleApiClient.PlayersService;
var clansService = clashRoyaleApiClient.ClansService;
clashRoyaleApiClient
contains all necessary clients.
First, you need to install Microsoft.Extensions.DependencyInjection
NuGet package as follows
dotnet add package Microsoft.Extensions.DependencyInjection
Register necessary dependencies to ServiceCollection
as follows
var serviceProvider = new ServiceCollection()
.AddClashRoyaleApiClient("<yor token>")
.BuildServiceProvider();
Or
var serviceProvider = new ServiceCollection()
.AddClashRoyaleApiClient(new ApiOptions("<your token>"))
.BuildServiceProvider();
Getting services:
var cardsService = serviceProvider.GetRequiredService<ICardsService>();
var challengesService = serviceProvider.GetRequiredService<IChallengesService>();
var clansService = serviceProvider.GetRequiredService<IClansService>();
var globalTournamentsService = serviceProvider.GetRequiredService<IGlobalTournamentsService>();
var locationsService = serviceProvider.GetRequiredService<ILocationsService>();
var playersService = serviceProvider.GetRequiredService<IPlayersService>();
var tournamentsService = serviceProvider.GetRequiredService<ITournamentsService>();
There is an extension that supports Microsoft.Extensions.Configuration
to store the ApiOptions
configuration as follows
{
"ApiOptions": {
"BearerToken": "<your token>",
"ApiAddress": "https://api.clashroyale.com",
"ApiVerstion": "v1",
"UseProxy": false,
"ProxyAddress": "https://proxy.royaleapi.dev"
}
}
string basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
var configuration = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var serviceProvider = new ServiceCollection()
.AddClashRoyaleApiClient(provider => {
//you can use provider to get any required service needed to initialize your ApiOptions
return configuration.GetApiOptionsSection("<sectionName>"); //if you don't specify the sectionName it will be "ApiOptions" by default
})
.BuildServiceProvider();
Licensed under MIT, see LICENSE for the full text.