MageCorp.ClashRoyaleApi.Client 2.1.1

dotnet add package MageCorp.ClashRoyaleApi.Client --version 2.1.1                
NuGet\Install-Package MageCorp.ClashRoyaleApi.Client -Version 2.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MageCorp.ClashRoyaleApi.Client" Version="2.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MageCorp.ClashRoyaleApi.Client --version 2.1.1                
#r "nuget: MageCorp.ClashRoyaleApi.Client, 2.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MageCorp.ClashRoyaleApi.Client as a Cake Addin
#addin nuget:?package=MageCorp.ClashRoyaleApi.Client&version=2.1.1

// Install MageCorp.ClashRoyaleApi.Client as a Cake Tool
#tool nuget:?package=MageCorp.ClashRoyaleApi.Client&version=2.1.1                

<img src="https://raw.githubusercontent.com/rodrigopiccelli/MageCorp.ClashRoyaleApi.Client/master/icon.png" width="28" height="28" title="Package Logo"> MageCorp.ClashRoyaleApi.Client <a href="https://www.nuget.org/packages/MageCorp.ClashRoyaleApi.Client" align="right" target="_blank"><img alt="NuGet Version" src="https://img.shields.io/nuget/v/MageCorp.ClashRoyaleApi.Client?color=004880&style=for-the-badge" align="right" /></a>

Client library (C# wrapper) written in .NET (9.0) that provides an easy way to interact with the official Clash Royale API directly or through proxy

Supported Platforms

  • .Net 9.0

Features

  • Dependency injection ready (can also be used standalone, see below)
  • Supports async calls.

Table of Contents

  1. Installation
  2. Usage
  3. License

<a name="installation"></a> Installation

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

<a name="usage"></a> Usage

<a name="standalone-initialization"></a> Standalone Initialization

If you do not want to use any DI framework, you have to instantiate ClashRoyaleApiClient as follows.

<a name="clashroyaleapistandalone"></a> ClashRoyaleApiClient Standalone Usage
Using Default HttpClient
ClashRoyaleApiOptions apiOptions = new("<your token>");
var clashRoyaleApiClient = ClashRoyaleApiClient.Create(apiOptions);
var playersService = clashRoyaleApiClient.PlayersService;
var clansService = clashRoyaleApiClient.ClansService;
Using Custom HttpClient
ClashRoyaleApiOptions apiOptions = new("<your token>");
HttpClient httpClient = new HttpClient(new SocketsHttpHandler { // Custom configuration for HttpClient }); 
var clashRoyaleApiClient = ClashRoyaleApiClient.Create(apiOptions, httpClient);
var playersService = clashRoyaleApiClient.PlayersService;
var clansService = clashRoyaleApiClient.ClansService;
Using IHttpClientFactory
ClashRoyaleApiOptions apiOptions = new("<your token>");
IServiceCollection services = new ServiceCollection();
services.AddHttpClient();
IServiceProvider serviceProvider = services.BuildServiceProvider();
IHttpClientFactory httpClientFactory = serviceProvider.GetRequiredService();
var clashRoyaleApiClient = ClashRoyaleApiClient.Create(apiOptions, httpClientFactory);
var playersService = clashRoyaleApiClient.PlayersService;
var clansService = clashRoyaleApiClient.ClansService;

clashRoyaleApiClient contains all necessary clients.

<a name="di-initialization"></a> Microsoft.Extensions.DependencyInjection Initialization

Register necessary dependencies to ServiceCollection as follows

var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient("<your token>")
    .BuildServiceProvider();

Or

var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient(new ClashRoyaleApiOptions("<your token>"))
    .BuildServiceProvider();

Or

var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient(provider => {
        //you can use provider to get any required service needed to initialize your ClashRoyaleApiOptions
        return new ClashRoyaleApiOptions(...);
    })
    .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>();
var leaderboardsService = serviceProvider.GetRequiredService<ILeaderboardsService>();
var filesService = serviceProvider.GetRequiredService<IFilesService>();
<a name="using-configuration"></a> Using Configuration

There is an extension that supports Microsoft.Extensions.Configuration to store the ClashRoyaleApiOptions configuration as follows

{
  "ClashRoyaleApiOptions": {
    "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();

//if you don't specify the sectionName it will be "ClashRoyaleApiOptions" by default
var clashRoyaleApiOptions = configuration.GetClashRoyaleApiOptionsSection("<sectionName>");
    
var serviceProvider = new ServiceCollection()
    .AddClashRoyaleApiClient(clashRoyaleApiOptions)
    .BuildServiceProvider();

<a name="license"></a> License

Licensed under MIT, see LICENSE for the full text.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 201 3/7/2025
2.0.0 103 2/21/2025
1.5.2 108 2/2/2025
1.5.1 99 1/22/2025
1.5.0 133 1/5/2025 1.5.0 is deprecated because it has critical bugs.
1.4.8 128 7/12/2024
1.4.7 134 7/9/2024 1.4.7 is deprecated because it has critical bugs.
1.4.5 123 5/31/2024
1.4.4 151 3/2/2024
1.4.3 224 12/15/2023
1.3.1 191 7/7/2023 1.3.1 is deprecated because it is no longer maintained.