#pokemon #rest #api

pokemontcgio

An interface for interacting with the pokemontcg.io REST API

1 unstable release

0.1.0 Aug 27, 2024

#778 in Web programming

MIT license

46KB
1K SLoC

Pokémon TCG IO API Wrapper

This is a wrapper for the REST API of pokemontcg.io that uses builder patterns inspired by reqwest.

Usage

Configuration

TODO

Using With an API Key

let client = Client::with_api_key("API_KEY");

Cards

Fetching a single card

let client = Client::with_api_key("API_KEY");
let card = client.get_card("swsh4-183").await?;
match card {
	Some(c) => println!("{:?}", c),
	None => println!("No card found!")
}

Searching for cards

let client = Client::with_api_key("API_KEY");
// Fetch cards with no filters
let cards = client.search_cards().send().await?;
match cards {
	Some(c) => println!("{:?}", c),
	None => println!("No cards found!")
}

// search_cards returns a builder with a number of methods to add filters
let cards = client
	.search_cards()
	.query("name:charizard")
	.page(2)
	.page_size(5)
	.order_by("rarity")
	.select("hp,flavor_text")
	.send()
	.await?;
match cards {
	Some(c) => println!("{:?}", c),
	None => println!("No cards found!")
}

Sets

All the same functions for cards exist for sets as well

let client = Client::with_api_key("API_KEY");
let set = client.get_set("swsh4").send().await?;

match set {
	Some(c) => println!("{:?}", c),
	None => println!("No set found!")
}

// Fetch sets with no filters
let sets = client.search_sets().send().await?;
match sets {
	Some(c) => println!("{:?}", c),
	None => println!("No sets found!")
}

// search_sets returns a builder with a number of methods to add filters
let sets = client
	.search_sets()
	.query("series:Sword & Shield")
	.page(4)
	.page_size(1)
	.order_by("total")
	.select("printed_total,total")
	.send()
	.await?;
match sets {
	Some(c) => println!("{:?}", c),
	None => println!("No sets found!")
}

Types, Subtypes, Supertypes and Rarities

These types only provide methods for fetching them all

let client = Client::with_api_key("API_KEY");

// All are Vec<String>
let types = client.get_types().send().await?;
let subtypes = client.get_subtypes().send().await?;
let supertypes = client.get_supertypes().send().await?;
let rarities = client.get_rarities().send().await?;

Dependencies

~7–18MB
~239K SLoC