#http-request #bevy #run-time #async #within #web

bevy_mod_reqwest

使用reqwest的Bevy HTTP客户端,专注于在Bevy运行时内简化使用

19个版本 (6个重大更改)

0.16.0 2024年8月5日
0.15.0 2024年7月4日
0.15.0-dev2024年6月30日
0.14.0 2024年2月20日
0.11.0 2023年7月12日

#107 in HTTP客户端

Download history 35/week @ 2024-05-03 26/week @ 2024-05-10 92/week @ 2024-05-17 156/week @ 2024-05-24 42/week @ 2024-05-31 60/week @ 2024-06-07 275/week @ 2024-06-14 80/week @ 2024-06-21 178/week @ 2024-06-28 106/week @ 2024-07-05 8/week @ 2024-07-12 13/week @ 2024-07-19 202/week @ 2024-07-26 251/week @ 2024-08-02 143/week @ 2024-08-09 182/week @ 2024-08-16

每月下载量 779

MIT 协议

32KB
286

bevy_mod_reqwest

crates.io docs.rs

此crate在尝试使用reqwest与bevy结合时非常有用,无需处理异步操作,并且它支持Web和本地(目前仅在x86_64和wasm上进行了测试)

Bevy版本 bevy_mod_reqwest版本
0.14 0.15
0.13 0.14
0.12 0.12 - 0.13

示例

use std::time::Duration;

use bevy::{log::LogPlugin, prelude::*, time::common_conditions::on_timer};
use bevy_mod_reqwest::*;

fn send_requests(mut client: BevyReqwest) {
    let url = "https://bored-api.appbrewery.com/random";

    // use regular reqwest http calls, then poll them to completion.
    let reqwest_request = client.get(url).build().unwrap();

    client
        // Sends the created http request
        .send(reqwest_request)
        // The response from the http request can be reached using an observersystem
        .on_response(|trigger: Trigger<ReqwestResponseEvent>| {
            let response = trigger.event();
            let data = response.as_str();
            let status = response.status();
            // let headers = req.response_headers();
            bevy::log::info!("code: {status}, data: {data:?}");
        })
        // In case of request error, it can be reached using an observersystem
        .on_error(|trigger: Trigger<ReqwestErrorEvent>| {
            let e = &trigger.event().0;
            bevy::log::info!("error: {e:?}");
        });
}

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_plugins(LogPlugin::default())
        .add_plugins(ReqwestPlugin::default())
        .add_systems(
            Update,
            send_requests.run_if(on_timer(Duration::from_secs(5))),
        )
        .run();
}

依赖项

~37–76MB
~1.5M SLoC