PokeApi.Models
1.0.25
dotnet add package PokeApi.Models --version 1.0.25
NuGet\Install-Package PokeApi.Models -Version 1.0.25
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="PokeApi.Models" Version="1.0.25" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PokeApi.Models" Version="1.0.25" />
<PackageReference Include="PokeApi.Models" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PokeApi.Models --version 1.0.25
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PokeApi.Models, 1.0.25"
#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.
#:package PokeApi.Models@1.0.25
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PokeApi.Models&version=1.0.25
#tool nuget:?package=PokeApi.Models&version=1.0.25
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PokeApi.Models
C# models for PokéAPI data, to be used with:
- REST API with https://pokeapi.co endpoints,
- files data with https://github.com/PokeApi/api-data JSON files
Package is published automatically whenever the upstream PokeAPI/api-data repository is updated. The package is always in sync with the latest schemas.
Usage
dotnet add package PokeApi.Models
Deserializing an API response
using System.Net.Http.Json;
using PokeApi.Models;
var http = new HttpClient { BaseAddress = new Uri("https://pokeapi.co") };
// Fetch a single Pokémon by id or name
var pokemon = await http.GetFromJsonAsync<Pokemon>(
Pokemon.RestEndpoint.Replace("{id}", "pikachu")
);
Console.WriteLine(pokemon?.Name); // "pikachu"
Console.WriteLine(pokemon?.BaseExperience); // 112
Deserializing an JSON data
using PokeApi.Models;
var pokemon = JsonSerializer.Deserialize<Pokemon>(
Path.Combine("../pokeapi/api-data/data", Pokemon.FileEndpoint)
);
// or using JsonTypeInfo from PokeApiJsonContext
var pokemon = JsonSerializer.Deserialize(
Path.Combine("../pokeapi/api-data/data", Pokemon.FileEndpoint),
PokeApiJsonContext.Default.Pokemon
);
Console.WriteLine(pokemon?.Name); // "pikachu"
Console.WriteLine(pokemon?.BaseExperience); // 112
Using the Endpoint constant
Each class exposes endpoints that reflect PokeAPI URL and paths patterns:
// File endpoint
Console.WriteLine(Version.FileEndpoint); // "/api/v2/version/$id/index.json"
// List file endpoint
Console.WriteLine(Version.FileEndpointList); // "/api/v2/version/index.json"
// REST endpoint
Console.WriteLine(Version.RestEndpoint); // "/api/v2/version/{id}/"
// List REST endpoint
Console.WriteLine(Version.RestEndpointList); // "/api/v2/version/"
// Build a URL
var url = $"https://pokeapi.co{Version.RestEndpoint}".Replace("{id}", "cheri");
// Build a file path
var url = $"./pokeapi/api-data/data{Version.FileEndpoint}".Replace("$id", "cheri");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.