MST
星途 面试题库

面试题:Rust中reqwest库API调用的基础配置

在Rust中使用reqwest库进行简单的GET请求调用API,假设API地址为'https://example.com/api/data',请编写代码实现,并处理可能出现的错误。
21.9万 热度难度
编程语言Rust

知识考点

AI 面试

面试题答案

一键面试
use reqwest;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let response = reqwest::get("https://example.com/api/data").await?;
    let body = response.text().await?;
    println!("Response body: {}", body);
    Ok(())
}