2 个版本

0.1.1 2021年6月29日
0.1.0 2021年6月29日

#29 in #json-api

BSD-3-Clause 许可

52KB
460

mealdb-rs

此 Rust 包提供了一个基于 reqwest 的异步接口,用于访问 themealdb.com

用法

目前,此包仅支持 json API v1 端点。

要使用此包,实例化 API 封装的一个实例。

use mealdb::preamble::*;

#[tokio::main]
pub async fn main() {
    println!("hello, world!");

    // Create handle to the API
    let api = mealdb::V1::new("https://www.themealdb.com", "<YOUR API KEY HERE>");
    // ...
    }

V1 API 封装公开了 themealdb API 的支持方法。

例如,获取所有包含 chicken 标题的菜肴

    // Searching for meals that contain a keyword
    println!("finding all meals with `chicken` in the name...");
    let meals = api
        .search_meal_by_name("chicken")
        .await
        .expect("query failed.")
        .expect("no results.");
    meals
        .iter()
        .for_each(|meal| println!("meal name :: {:?} meal id :: {}", meal.name, meal.id));

依赖项

~4–19MB
~252K SLoC