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

bevy_mod_reqwest

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

19 releases (6 breaking)

0.16.0 Aug 5, 2024
0.15.0 Jul 4, 2024
0.15.0-dev Jun 30, 2024
0.14.0 Feb 20, 2024
0.11.0 Jul 12, 2023

#106 in HTTP client

Download history 12/week @ 2024-07-17 40/week @ 2024-07-24 325/week @ 2024-07-31 183/week @ 2024-08-07 136/week @ 2024-08-14 202/week @ 2024-08-21 127/week @ 2024-08-28 139/week @ 2024-09-04 207/week @ 2024-09-11 173/week @ 2024-09-18 178/week @ 2024-09-25 162/week @ 2024-10-02 88/week @ 2024-10-09 97/week @ 2024-10-16 117/week @ 2024-10-23 216/week @ 2024-10-30

552 downloads per month

MIT license

32KB
286 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.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

~39–79MB
~1.5M SLoC