Network Backends
The engine has an HTTP API and no HTTP client of its own. renzora::net (the renzora_net_api layer) describes a request and waits for the answer; renzora_net (NetPlugin) runs the pump that moves requests and answers each frame; and something implementing renzora::net_backend::Backend opens the socket. In the editor that something is renzora_http.
renzora_http is an Editor-scope plugin. The editor uses it for the Marketplace and its account features. A shipped game has no HTTP client unless one is installed as a Runtime plugin, and without one every request fails at once with "no network backend is loaded": nothing panics, nothing hangs, and the game carries on.
This page is about HTTP. Game replication (renzora_network) is a different system: per-frame and latency-critical, it would gain a frame of latency and a copy per packet from a once-a-frame request queue. See Networking.
Why HTTP is behind a boundary
Size. ureq plus the TLS stack under it (rustls, ring, webpki, the platform certificate verifiers) is around twenty packages. Behind the boundary they belong to one crate, and a build without it ships without the stack.
Different platforms need different clients. A browser build wants fetch, where TLS, certificates and the connection pool come with the browser. A console wants the platform's own certified HTTP library. A studio behind a corporate proxy wants its own. None of that is expressible while the client is a dependency of the engine.
What each side owns
The engine (renzora::net, renzora_net) | the request builder, the blocking facade, the frame pump, tag bookkeeping, and every decision about what to fetch and what the answer means |
| The backend | DNS, connect, TLS, headers, reading bodies |
The backend knows nothing about the Marketplace, auth tokens, JSON shapes or retry policy. It moves bytes.
It must not block
Backend::start is called from inside the frame. A backend that performed the transfer there would stall the editor for a round trip, so the contract is queue and poll: start hands the work off and returns, and poll is called once per frame to collect whatever finished. The blocking facade the engine offers on top works by parking the calling thread while frames keep running, which only holds together because this side stays asynchronous.
Capabilities are answered, not assumed
init returns a BackendInfo with a Caps bitfield: STREAM, CANCEL, HEADERS. The engine sends no cancellation to a backend that did not claim CANCEL, and expects a streaming request to arrive in pieces when STREAM is set. A backend that claims streaming and delivers one body at the end leaves a streaming consumer waiting for pieces that never come.
An HTTP error status is not an error
A 404 is a successful request whose response says 404. Only transport failure (DNS, connect, TLS, timeout, a read that died mid-body) is EventKind::Error. This matters: renzora.com answers a failed call with a 400 and a body like {"error": "asset name already taken"}, and a client that turned the status into an error would throw away the one thing worth showing the user.
Using it
use renzora::net::Request;
// On a background thread, never from a system (see below).
let assets: Vec<Asset> = Request::get(&url)
.maybe_bearer(token.as_deref())
.send()?
.json()?;
Response::json treats a non-2xx status as an error and surfaces the server's own {"error": ...} message, falling back to HTTP <status>. Response::text and the raw body cover everything else; the body is bytes because many callers fetch images.
Streaming:
let mut stream = Request::post(&endpoint).json(&payload).send_stream()?;
for chunk in &mut stream {
print!("{}", chunk.text());
}
if let Some(e) = stream.error() {
// the transfer died partway
}
Chunks are whatever each read returned, so a line or an event can straddle two of them. The transport knows nothing about framing (NDJSON and server-sent events end a frame differently), so a consumer that parses lines must reassemble them across chunks.
renzora::net::fetch(request) and fetch_stream(request) are the free-function forms of send and send_stream.
Never block on a request from a system
A system runs inside the frame the pump needs to make progress, so blocking there waits for something that cannot happen until it returns. On the threads systems run on (the main thread and Bevy's compute task pool) the wait gives up with Error::NoPump after two seconds rather than hanging. A thread you spawned yourself waits through slow frames (the editor's first frames can take seconds while plugins load) and gives up only after thirty seconds with no frame at all. Requests time out after 60 seconds by default.
Spawn a thread, or use the inbox pattern renzora_scripting uses for its HTTP hook (HttpInbox): start the request, and pick up the answer in a later frame.
Writing a backend
use bevy::prelude::*;
use renzora::net_backend::*;
#[derive(Default)]
struct MyClient {
// ...
}
impl Backend for MyClient {
fn name(&self) -> &str {
"my_client"
}
fn init(&mut self) -> Result<BackendInfo, String> {
todo!("build a client")
}
fn start(&mut self, request: &Request, body: &[u8]) -> Result<(), String> {
todo!("hand the transfer to a worker")
}
fn poll(&mut self) -> Vec<Event> {
todo!("drain what finished")
}
// `shutdown` and `cancel` have defaults
}
pub struct MyHttpPlugin;
impl Plugin for MyHttpPlugin {
fn build(&self, app: &mut App) {
app.add_net_backend(MyClient::default());
}
}
renzora::plugin!(MyHttpPlugin, Runtime);
Runtime scope is what makes it load in a shipped game.
- A panicking backend is contained, then disabled. The pump wraps every call in
catch_unwind, so one malformed header does not take the process down; requests already handed over fail at once instead of waiting out their timeouts, and the backend is poisoned rather than retried. - One backend is used. A request carries nothing to choose between clients by, and splitting a session's cookies and connection pool across two would break both.
add_net_backendkeeps the first registration and logs an error for any other.
The bundled backend
renzora_http is ureq with rustls, one worker thread per request: the editor's traffic peaks at a Marketplace page and its thumbnails, each dominated by waiting on a socket, so a pool would only add an arbitrary limit.
http_status_as_error(false). Without itureqturns a 4xx into an error and discards the body, the exact behaviour the section above exists to prevent.max_bytesis enforced as the body arrives, not afterwards. The callers that set it fetch images from URLs a server chose, and a cap applied once the bytes are in memory protects nothing.
There is no WebSocket support in the contract: no caller needs one today.