#http-request #bevy #run-time #web-native #async #mod #entity

bevy_mod_reqwest

use reqwest with the bevy runtime in the same way on both web and native

15 unstable releases (4 breaking)

0.14.2 Apr 18, 2024
0.14.0 Feb 20, 2024
0.12.0 Nov 13, 2023
0.11.0 Jul 12, 2023

#590 in Game dev

Download history 28/week @ 2024-01-07 58/week @ 2024-01-14 85/week @ 2024-01-28 174/week @ 2024-02-04 118/week @ 2024-02-11 345/week @ 2024-02-18 191/week @ 2024-02-25 137/week @ 2024-03-03 169/week @ 2024-03-10 165/week @ 2024-03-17 110/week @ 2024-03-24 190/week @ 2024-03-31 105/week @ 2024-04-07 424/week @ 2024-04-14 214/week @ 2024-04-21

933 downloads per month

MIT license

37KB
348 lines

bevy_mod_reqwest

This crate helps when trying to use reqwest with bevy, without having to deal with async stuff, and it works on both web and and native ( only tested on x86_64 and wasm for now)

Example

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://www.boredapi.com/api/activity";
    let req = client.get(url).build().unwrap();
    // will run the callback, and remove the created entity after callback
    client.send(
        req,
        On::run(|req: Listener<ReqResponse>| {
            let res = req.as_str();
            bevy::log::info!("return data: {res:?}");
        }),
    );
}

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(2))),
        )
        .run();
}

Dependencies

~43–88MB
~1.5M SLoC