Skip to main content

Crate net_backend_client

Crate net_backend_client 

Source
Expand description

A Rust client for net_backend_server, built on the shared types of net_backend_protocol.

For Rust apps that do not use Bevy (other engines, tools, bots, command-line programs); Bevy games use bevy_net_backend.

  • Client (async, tokio): typed calls for every route (Client::call with any HttpCall), the session (login, register, Steam, automatic refresh before expiry, one refresh at a time, rotating refresh tokens reported through TokenUpdates, logout), errors as the server’s codes (Error::Api).
  • blocking::Client: the same client for programs without a runtime, with Reply::try_take for game loops.
  • Feature ws: the WebSocket (module ws): typed requests, pushes, heartbeats, reconnects that obey the close codes.
  • Features ssh / sftp / ssh-rsa: SSH and SFTP to the server machine’s OpenSSH (module ssh), for admin tools.
use net_backend_client::protocol::auth::{GetAccount, LoginRequest};
use net_backend_client::protocol::storage::{GetObject, PutObject, WriteObject};
use net_backend_client::Client;

let client = Client::new("https://api.example.com")?;
client.login(LoginRequest::new("player@example.com", "a long password")).await?;
let me = client.call(&GetAccount::new()).await?;
client.call(&WriteObject::new("saves", "slot-1", PutObject::new(serde_json::json!({"level": 3})))).await?;
let save = client.call(&GetObject::new("saves", "slot-1")).await?;
println!("{:?} is on level {}", me.display_name, save.value["level"]);

The README is the full manual.

Re-exports§

pub use net_backend_protocol as protocol;

Modules§

blocking
The blocking interface: the same client for programs without an async runtime (game loops of other engines, simple tools). Always compiled.
sshssh
SSH to the server machine’s OpenSSH (feature ssh), and SFTP on it (feature sftp). For admin tools: deploy scripts, log tails, backups. It never goes through net_backend_server.
wsws
The WebSocket (feature ws): one connection per client carrying typed requests and answers (WsCall), server pushes (ServerPush), heartbeats and reconnects that obey the protocol’s close codes.

Structs§

Client
The async client (tokio). Cheap to clone: clones share the connection pool and the session.
ClientBuilder
Settings for a Client (Client::builder). Nothing is checked or opened until build.
Reply
The answer to one request that is on its way: exactly one Result arrives.
TokenUpdates
Every change of the session’s tokens, for the app to persist them (Client::token_updates).

Enums§

Error
Why a call, a connection or a command did not succeed.
HostKeyProblem
Why an SSH host key was refused (Error::HostKey).

Constants§

DEFAULT_MAX_RESPONSE_BYTES
The default limit of one HTTP answer body: 10 MiB (a full storage batch is about 4 MiB).
DEFAULT_TIMEOUT
The default deadline of one call: 15 s.
MAX_TIMEOUT
The longest deadline accepted: 1 hour.