Fetching Pokémon data from PokeAPI in Rust with reqwest and serde

PokeAPI is a free, read-only REST API with data on every Pokémon: types, stats, abilities, moves and more. It needs no API key, which makes it a good target for practising HTTP and JSON in Rust.
This post builds a command-line tool that takes a Pokémon name and prints its height, weight, and types. It uses reqwest for HTTP, serde to deserialize the JSON, and tokio as the async runtime.
Setting up the project
Section titled “Setting up the project”Install Rust with rustup if you haven’t already, then:
cargo new pokeapi_rustcd pokeapi_rustcargo add reqwest --features jsoncargo add serde --features derivecargo add tokio --features macros,rt-multi-threadThe resulting dependencies (versions current as of November 2026):
[dependencies]reqwest = { version = "0.13", features = ["json"] }serde = { version = "1", features = ["derive"] }tokio = { version = "1", features = ["macros", "rt-multi-thread"] }You don’t need serde_json as a direct dependency: reqwest’s json feature handles deserialization through Response::json.
Data structures and the request
Section titled “Data structures and the request”The /api/v2/pokemon/{name} response is large, but serde ignores fields you don’t declare, so the structs only need the parts you use. Put this in src/pokemon.rs:
use serde::Deserialize;
#[derive(Deserialize, Debug)]pub struct Pokemon { pub name: String, /// Height in decimetres pub height: u32, /// Weight in hectograms pub weight: u32, pub types: Vec<PokemonType>,}
#[derive(Deserialize, Debug)]pub struct PokemonType { #[serde(rename = "type")] pub type_data: TypeData,}
#[derive(Deserialize, Debug)]pub struct TypeData { pub name: String,}
pub async fn fetch_pokemon_data(pokemon_name: &str) -> Result<Pokemon, reqwest::Error> { let url = format!("https://pokeapi.co/api/v2/pokemon/{pokemon_name}"); reqwest::get(&url) .await? .error_for_status()? .json::<Pokemon>() .await}The JSON field is called type, which is a Rust keyword, so #[serde(rename = "type")] maps it to type_data.
error_for_status() matters here. For an unknown name, PokeAPI returns a 404 with a small error body that doesn’t match the Pokemon struct. Without that call, reqwest treats the 404 as a successful response and you’d get a confusing JSON decoding error instead of “404 Not Found”.
Printing the result
Section titled “Printing the result”mod pokemon;
use pokemon::{fetch_pokemon_data, PokemonType};use std::env;use std::process::ExitCode;
fn types_to_string(types: &[PokemonType]) -> String { types .iter() .map(|t| t.type_data.name.as_str()) .collect::<Vec<_>>() .join(", ")}
#[tokio::main]async fn main() -> ExitCode { let Some(pokemon_name) = env::args().nth(1) else { eprintln!("Usage: pokeapi_rust <pokemon_name>"); return ExitCode::FAILURE; };
match fetch_pokemon_data(&pokemon_name).await { Ok(pokemon) => { println!("Name: {}", pokemon.name); println!("Height: {:.1} m", pokemon.height as f32 / 10.0); println!("Weight: {:.1} kg", pokemon.weight as f32 / 10.0); println!("Types: {}", types_to_string(&pokemon.types)); ExitCode::SUCCESS } Err(error) => { eprintln!("Error: {error}"); ExitCode::FAILURE } }}PokeAPI reports height in decimetres and weight in hectograms, so dividing by 10 gives metres and kilograms. Returning ExitCode means the program exits non-zero on failure, which is useful if you script it.
Running it
Section titled “Running it”cargo run -- pikachuName: pikachuHeight: 0.4 mWeight: 6.0 kgTypes: electricAn unknown name (cargo run -- notapokemon) prints a 404 Not Found error and exits with status 1.
Next steps and gotchas
Section titled “Next steps and gotchas”- Cache responses. PokeAPI’s fair use policy asks clients to cache resources locally and limit how often they call the API. The data rarely changes, so writing each response to disk is an easy win.
- Reuse a
reqwest::Client.reqwest::getbuilds a new client per call. If you fetch many Pokémon, create oneClientand callclient.get(url)so connections are pooled. - Ready-made wrapper. PokeAPI’s docs list community wrapper libraries, including Rustemon for Rust, which caches responses automatically.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)