You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingPokeApiNet;
...// instantiate clientPokeApiClient pokeClient =newPokeApiClient();// get a resource by namePokemonhoOh=awaitpokeClient.GetResourceAsync<Pokemon>("ho-oh");// ... or by idItemclawFossil=awaitpokeClient.GetResourceAsync<Item>(100);
To see all the resources that are available, see the PokeAPI docs site.
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:
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 propertyPokemonSpeciesspecies=awaitpokeClient.GetResourceAsync(pikachu.Species);// to resolve a list of themList<Move>allMoves=awaitpokeClient.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=awaitclient.GetNamedResourcePageAsync<Berry>();// to specify a certain page, use the provided overloadsNamedApiResourceList<Berry>lotsMoreBerriesPage=awaitclient.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:
Refer to the PokeAPI documention to see which resources include a Name property.
IAsyncEnumerable Support
Two methods expose support for IAsyncEnumerable to make paging through all pages super simple: GetAllNamedResourcesAsync<T>() and GetAllApiResourcesAsync<T>(). Example:
awaitforeach(varberryRefinpokeClient.GetAllNamedResourcesAsync<Berry>()){// do something with each berry reference}
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 APIPokemonmew=awaitpokeClient.GetResourceAsync<Pokemon>(151);// another call to the same resource will fetch from the cachePokemonmewCached=awaitpokeClient.GetResourceAsync<Pokemon>("mew");
To clear the cache of data:
// clear all caches for both resources and pagespokeClient.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"