https://github.com/chnapy/pokeapi.models
Auto generated C# models for pokeapi.co data
https://github.com/chnapy/pokeapi.models
Last synced: about 1 month ago
JSON representation
Auto generated C# models for pokeapi.co data
- Host: GitHub
- URL: https://github.com/chnapy/pokeapi.models
- Owner: Chnapy
- License: mit
- Created: 2026-04-26T10:47:45.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-06-01T11:01:33.000Z (about 2 months ago)
- Last Synced: 2026-06-01T13:04:50.507Z (about 2 months ago)
- Language: C#
- Homepage: https://nuget.org/packages/PokeApi.Models
- Size: 102 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PokeApi.Models
C# models for [PokéAPI](https://pokeapi.co/) data, to be used with:
- REST API with https://pokeapi.co endpoints,
- files data with https://github.com/PokeApi/api-data JSON files
[](https://www.nuget.org/packages/PokeApi.Models)
[](https://dotnet.microsoft.com)
Package is published automatically whenever the upstream [PokeAPI/api-data](https://github.com/PokeAPI/api-data) repository is updated. The package is always in sync with the latest schemas.
---
## Usage
```sh
dotnet add package PokeApi.Models
```
### Deserializing an API response
```csharp
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.RestEndpoint.Replace("{id}", "pikachu")
);
Console.WriteLine(pokemon?.Name); // "pikachu"
Console.WriteLine(pokemon?.BaseExperience); // 112
```
### Deserializing an JSON data
```csharp
using PokeApi.Models;
var pokemon = JsonSerializer.Deserialize(
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:
```csharp
// 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");
```