use dotenv::{dotenv, var}; use serde::Deserialize; kvapi::api! { // `name` is the Struct name for the API name: MyExample // `base` will be the start of every URL within this API definition // vvv base: "https://www.random_example/will_not_work/" headers: { // this header is built at the time of `MyExample::new()`, // i.e., when the clients are initialised "User-Agent": "hello@me.com" // this header is built whenever a HTTP request is sent, because of // the use of `#[query]` #[query] "Date": "2012-01-01" } dict: { // this `query` appends a &String to the end of the URl // vvv #[rename: "category", query: var("USER_AGENT").unwrap()] "/category?id3563.com": MyType // <-- `MyType` is the Deserialize type // ^^^ // this node cannot correctly name to a Struct (given the numbers & `?`), // so we rename it to `category` } } // the serde "schema" #[derive(Deserialize)] struct MyType; #[tokio::main] async fn main() { dotenv().ok(); // `name` can call 'new()' to initiliase the API's clients // vvv let api = MyExample::new(); api.category.get().await.unwrap(); // ^^^ // `category` then called down here, which has access to `.get()`, which // fetches, and deserializes, our endpoint }