krabdex

Crates.iokrabdex
lib.rskrabdex
version0.1.0
created_at2026-01-18 00:16:37.892468+00
updated_at2026-01-18 00:16:37.892468+00
descriptionA type-safe, async Rust SDK for the PokeAPI
homepage
repositoryhttps://github.com/kodokoto/krabdex
max_upload_size
id2051466
size98,872
Jorge Martin Albeniz (kodokoto)

documentation

https://docs.rs/krabdex

README

krabdex

A type-safe, async Rust SDK for PokeAPI.

Features

  • Async client built on reqwest (rustls).
  • Strongly typed models for Pokémon and Generation resources.
  • Validated identifiers (PokemonName, GenerationName) and pagination types (Limit, PageRequest).
  • Error classification for HTTP status codes (including rate limiting).

Quick start

cargo add krabdex
use krabdex::{
    PokeApiClient,
    types::{PokemonName, GenerationName, GenerationRef, PokemonRef, Limit, PageRequest},
};

#[tokio::main]
async fn main() -> krabdex::Result<()> {
    // Default client (https://pokeapi.co/api/v2)
    let client = PokeApiClient::new()?;

    // Fetch by id or name
    let pikachu = client.pokemon(PokemonRef::Id(25)).await?;
    let ditto = client.pokemon(PokemonRef::Name(PokemonName::new("ditto")?)).await?;

    // Generations
    let gen1 = client.generation(GenerationRef::Name(GenerationName::new("generation-i")?)).await?;

    // Pagination
    let page = client.pokemon_list(PageRequest::first_page(Limit::new(10)?)).await?;

    println!("pikachu: {:?}", pikachu.name);
    println!("ditto: {:?}", ditto.name);
    println!("gen1: {:?}", gen1.name);
    println!("first page count: {}", page.results.len());
    Ok(())
}

Custom configuration

use url::Url;
use krabdex::{PokeApiClient, client::builder::PokeApiClientBuilder};

let client = PokeApiClientBuilder::new()
    .base_url(Url::parse("https://pokeapi.co/")?)
    .api_prefix("api/v2")
    .user_agent("krabdex-example/0.1.0")
    .build()?;

Errors

All operations return krabdex::Result<T> with rich krabdex::Error variants:

  • Transport for network/TLS/IO issues.
  • Api for non-2xx responses (NotFound, RateLimited, HttpStatus).
  • Deserialize when response payloads do not match expected models.
  • InvalidArgument for local validation failures (e.g., invalid names/limits).

Development

  • Tests: cargo test
  • Docs: cargo doc --no-deps --open
Commit count: 15

cargo fmt