PokeApiNet 3.0.10

.NET Standard 2.0
dotnet add package PokeApiNet --version 3.0.10
NuGet\Install-Package PokeApiNet -Version 3.0.10
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="PokeApiNet" Version="3.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PokeApiNet --version 3.0.10
#r "nuget: PokeApiNet, 3.0.10"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install PokeApiNet as a Cake Addin
#addin nuget:?package=PokeApiNet&version=3.0.10

// Install PokeApiNet as a Cake Tool
#tool nuget:?package=PokeApiNet&version=3.0.10

PokeApiNet

A .Net wrapper for the Pokemon API at https://pokeapi.co.

Targets .Net Standard 2.0+.

NuGet Build Status

Use

using PokeApiNet;

...

// instantiate client
PokeApiClient pokeClient = new PokeApiClient();

// get a resource by name
Pokemon hoOh = await pokeClient.GetResourceAsync<Pokemon>("ho-oh");

// ... or by id
Item clawFossil = await pokeClient.GetResourceAsync<Item>(100);

To see all the resources that are available, see the PokeAPI docs site.

Internally, PokeApiClient uses an instance of the HttpClient class. As such, instances of PokeApiClient are meant to be instantiated once and re-used throughout the life of an application.

PokeAPI uses navigation urls for many of the resource's properties to keep requests lightweight, but require subsequent requests in order to resolve this data. Example:

Pokemon pikachu = await pokeClient.GetResourceAsync<Pokemon>("pikachu");

pikachu.Species only has a Name and Url property. In order to load this data, an additonal request is needed; this is more of a problem when the property is a list of navigation URLs, such as the pikachu.Moves.Move collection.

GetResourceAsync includes overloads to assist with resolving these navigation properties. Example:

// to resolve a single navigation url property
PokemonSpecies species = await pokeClient.GetResourceAsync(pikachu.Species);

// to resolve a list of them
List<Move> allMoves = await pokeClient.GetResourceAsync(pikachu.Moves.Select(move => move.Move));

Paging

PokeAPI supports the paging of resources, allowing users to get a list of available resources for that API. Depending on the shape of the resource data, two methods for paging are included, along with overloads to allow for the specification of the page count limit and the page offset. Example:

// get a page of data (defaults to a limit of 20)
NamedApiResourceList<Berry> firstBerryPage = await client.GetNamedResourcePageAsync<Berry>();

// to specify a certain page, use the provided overloads
NamedApiResourceList<Berry> lotsMoreBerriesPage = await client.GetNamedResourcePageAsync<Berry>(60, 2);

Because the Berry resource has a Name property, the GetNamedResourcePageAsync() method is used. For resources that do not have a Name property, use the GetApiResourcePageAsync() method. Example:

ApiResourceList<ContestEffect> contestEffectPage = await client.GetApiResourcePageAsync<ContestEffect>();

Regardless of which method is used, the returning object includes a Results collection that can be used to pull the full resource data. Example:

Berry cheri = await client.GetResourceAsync<Berry>(firstBerryPage.Results[0]);

Refer to the PokeAPI documention to see which resources include a Name property.

Caching

Every resource and page response is automatically cached in memory, making all subsequent requests for the same resource or page pull cached data. Example:

// this will fetch the data from the API
Pokemon mew = await pokeClient.GetResourceAsync<Pokemon>(151);

// another call to the same resource will fetch from the cache
Pokemon mewCached = await pokeClient.GetResourceAsync<Pokemon>("mew");

To clear the cache of data:

// clear all caches for both resources and pages
pokeClient.ClearCache();

Additional overloads are provided to allow for clearing the individual caches for resources and pages, as well as by type of cache.

Build

dotnet build

Test

The test bank includes unit tests and integration tests. Integration tests will actually ping the PokeApi server for data while the unit tests run off of mocked data.

dotnet test --filter "Category = Unit"
dotnet test --filter "Category = Integration"
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
3.0.10 117 1/23/2023
3.0.9 628 9/16/2022
3.0.8 458 8/18/2022
3.0.7 228 8/17/2022
3.0.6 221 8/15/2022
3.0.5 737 6/17/2022
3.0.4 291 5/28/2022
3.0.3 2,258 7/17/2021
3.0.2 400 6/2/2021
3.0.1 368 4/15/2021
3.0.0 1,154 1/12/2020
2.0.0 579 8/14/2019
1.1.0 408 7/22/2019
1.0.0 447 5/9/2019