Crate bevy_ehttp

Source
Expand description

§bevy_ehttp

Crates.io Documentation MIT/Apache 2.0

A ehttp Bevy Plugin that works both on native and on WASM.

Simple request will invoke OnResponseString(pub Result<Response, String>) event once completed.

There is also option to call typed request that will allow to deserialize response to given type by using RequestBundle<T>. More details available in typed.rs example.

§Example

use bevy::{prelude::*, time::common_conditions::on_timer};
use bevy_ehttp::prelude::*;

fn main() {
    App::new()
        .add_plugins((MinimalPlugins, HttpPlugin))
        .add_systems(
            Update,
            send_request.run_if(on_timer(std::time::Duration::from_secs(1))),
        )
        .add_observer(on_response)
        .run();
}

fn send_request(mut commands: Commands) {
    let req = ehttp::Request::get("https://api.ipify.org/eee?format=json");
    commands.spawn(HttpRequest(req));
}

fn on_response(t: Trigger<OnResponseString>) {
    match &**t {
        Ok(response) => println!("[{:?}]: {:?}", t.url(), response.text()),
        Err(e) => println!("response error: {:?}", e),
    }
}

§Thanks

Big thanks to the creators of the Bevy Engine and to the foxzool user for creating bevy_http_client that this plugin is based on.

§License

bevy_ehttp is dual-licensed under MIT and Apache 2.0 at your option.

§Bevy compatibility table

Bevy versionCrate version
0.160.5
0.150.4
0.140.3
0.130.2
0.120.1

Modules§

prelude

Structs§

HttpClientSetting
Settings of http client. can set the max concurrent request.
HttpPlugin
Plugin that provides support for send http request and handle response.
HttpRequest
wrap for ehttp request
OnResponseString
Wraps ehttp response without parsing it. For parsed version use ``
RequestTask
task for ehttp response result

Traits§

RequestResponseExt