ApiFootball 2.1.0
dotnet add package ApiFootball --version 2.1.0
NuGet\Install-Package ApiFootball -Version 2.1.0
<PackageReference Include="ApiFootball" Version="2.1.0" />
<PackageVersion Include="ApiFootball" Version="2.1.0" />
<PackageReference Include="ApiFootball" />
paket add ApiFootball --version 2.1.0
#r "nuget: ApiFootball, 2.1.0"
#:package ApiFootball@2.1.0
#addin nuget:?package=ApiFootball&version=2.1.0
#tool nuget:?package=ApiFootball&version=2.1.0
CSharpApiFootball
DI compatible C# API client for api-football.com. Only v3 endpoints will be supported. A list of availble endpoints can be found below, not a lot of them are there yet but this is a work in progress. It should work with both api-sports and rapidapi keys, but because I do not have a rapidapi key I cannot test this. If you would like to help out, feel free to open a pull request!
This project is not affiliated with api-football or api-sports.
Example
var key = "your api key";
var host = Host
.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureServices(services => {
services
.AddApiFootball(key); // Configure ApiFootball client
}).Build();
var serviceScope = host.Services.CreateScope();
var provider = serviceScope.ServiceProvider;
// Print Dutch Eredivisie games and final scores for the 2022 season
var fixturesClient = provider.GetRequiredService<IFixturesClient>();
var fixtures = await fixturesClient.GetFixtures(league:88, season:2022);
// To throw an exception in case of errors
timezones.EnsureSuccess();
fixtures.Response
.Select(fix => $"{fix.Teams.Home.Name, 20} - {fix.Teams.Away.Name, -20} {" ", 10} {fix.Goals.Home} - {fix.Goals.Away}")
.ToList()
.ForEach(Console.WriteLine);
// Print all timezones
var timezoneClient = provider.GetRequiredService<ITimezoneClient>();
var timezones = await timezoneClient.GetTimezones();
// To throw an exception in case of errors
timezones.EnsureSuccess();
timezones.Response.ForEach(Console.WriteLine);
Free API keys are limited to 10 requests per minute at the time of writing.
Use the EnsureSuccess()
method to throw an ApiFootballException
in case of errors or handle them yourself through
the Errors
object on the response.
Error handling
By default, no exception are thrown when ApiFootball returns a valid response object containing errors.
You can enable throwing exceptions by setting the ThrowOnError
property to true
when you register it in the DI
container.
services.AddApiFootball(options =>
{
options.ApiKey = key;
options.ThrowOnError = true;
});
Supported endpoints
Here you can find a list of all the endpoints that are currently supported and which interface to use to call them.
Endpoint | C# |
---|---|
/countries |
ICountriesClient.GetCountries |
/fixtures |
IFixturesClient.GetFixtures |
/fixtures/rounds |
IFixturesClient.GetRounds |
/leagues |
ILeaguesClient.GetLeagues |
/leagues/seasons |
ILeaguesClient.GetSeasons |
/standings |
IStandingsClient.GetStandings |
/teams |
ITeamsClient.GetTeamsInformation |
/teams/seasons |
ITeamsClient.GetTeamsSeasons |
/teams/countries |
ITeamsClient.GetTeamsCountries |
/timezone |
ITimezoneClient.GetTimezones |
/venues |
IVenuesClient.GetVenues |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Http (>= 6.0.0)
-
net8.0
- Microsoft.Extensions.Http (>= 6.0.0)
-
net9.0
- Microsoft.Extensions.Http (>= 6.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.