#http-client #http-request #bevy #async-http #run-time #web #focus

bevy_mod_reqwest

Bevy http client using reqwest, with a focus on simple usage within the bevy runtime

20 releases (7 breaking)

new 0.17.0 Nov 11, 2024
0.15.0 Jul 4, 2024
0.14.0 Feb 20, 2024
0.12.0 Nov 13, 2023
0.11.0 Jul 12, 2023

#203 in Game dev

Download history 202/week @ 2024-07-26 251/week @ 2024-08-02 143/week @ 2024-08-09 183/week @ 2024-08-16 135/week @ 2024-08-23 162/week @ 2024-08-30 172/week @ 2024-09-06 170/week @ 2024-09-13 176/week @ 2024-09-20 155/week @ 2024-09-27 183/week @ 2024-10-04 51/week @ 2024-10-11 114/week @ 2024-10-18 134/week @ 2024-10-25 255/week @ 2024-11-01 301/week @ 2024-11-08

814 downloads per month

MIT license

32KB
287 lines

bevy_mod_reqwest

crates.io docs.rs

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)

Bevy version bevy_mod_reqwest version
0.14 0.15 - 0.17
0.13 0.14
0.12 0.12 - 0.13

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://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();
}

Dependencies

~41–80MB
~1.5M SLoC