7 releases (4 breaking)

new 0.5.2 Apr 23, 2024
0.5.1 Feb 28, 2024
0.4.0 Feb 19, 2024
0.3.0 Feb 4, 2024
0.1.0 Aug 28, 2023

#746 in Game dev

Download history 304/week @ 2024-02-19 174/week @ 2024-02-26 10/week @ 2024-03-04 10/week @ 2024-03-11 14/week @ 2024-03-18 76/week @ 2024-04-01 4/week @ 2024-04-08 10/week @ 2024-04-15

96 downloads per month

MIT/Apache

32KB
390 lines

bevy_http_client

Crates.io crates.io Documentation MIT/Apache 2.0

A simple HTTP client Bevy Plugin for both native and WASM.

Example

use bevy::{prelude::*, time::common_conditions::on_timer};
use bevy_http_client::prelude::*;
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize, Default)]
pub struct IpInfo {
    pub ip: String,
}

fn main() {
    let mut app = App::new();
    app.add_plugins((MinimalPlugins, HttpClientPlugin))
        .add_systems(Update, handle_response)
        .add_systems(
            Update,
            send_request.run_if(on_timer(std::time::Duration::from_secs(1))),
        );
    app.register_request_type::<IpInfo>();
    app.run();
}

fn send_request(mut ev_request: EventWriter<TypedRequest<IpInfo>>) {
    ev_request.send(
        HttpClient::new()
            .get("https://api.ipify.org?format=json")
            .with_type::<IpInfo>(),
    );
}

fn handle_response(mut ev_response: EventReader<TypedResponse<IpInfo>>) {
    for response in ev_response.read() {
        println!("ip: {}", response.ip);
    }
}

Supported Versions

bevy bevy_http_client
0.13 0.4, 0,5
0.12 0.3
0.11 0.1

License

Dual-licensed under either

  • MIT
  • Apache 2.0

Dependencies

~39–80MB
~1M SLoC