Expand description
Typed protocol routes: a handler for an HttpCall is mounted at the call’s own path with the
call’s own method, takes the decoded call (Call<C>) and answers the call’s own response type
(Reply<C>). Path, method, payload and answer come from the protocol, so they cannot drift
between the server, its OpenAPI document and the clients.
Authentication is enforced by the mount: a route whose C::ROUTE.auth is true answers 401
(unauthorized / token_expired, or the authenticator’s 403 banned) to a request without a
valid token BEFORE the handler runs, whether or not the handler takes an
AuthContext. The flag in the protocol (and in the OpenAPI document) is a
guarantee, also for a game’s own HttpCall mounted with
NetBackendServer::call or call_route!.
use net_backend_server::http::call::{Call, CallResult, Reply};
use net_backend_server::protocol::chat::{ListRooms, RoomInfo, RoomKind};
use net_backend_server::protocol::{Page, RoomId};
use net_backend_server::{AuthContext, Config, NetBackendServer};
async fn rooms(_who: AuthContext, Call(call): Call<ListRooms>) -> CallResult<ListRooms> {
let _ = call.page;
Ok(Reply::new(Page::new(vec![RoomInfo::new(RoomId(1), RoomKind::Room).with_key("world")], None)))
}
// Mounted at GET /v1/chat/rooms (from `ListRooms::ROUTE`), undocumented; documented handlers
// carry `#[utoipa::path(..)]` and go through `call_route!(ListRooms, rooms)`.
let server = NetBackendServer::new(Config::default()).call::<ListRooms, _, _, _>(rooms);Structs§
- Call
- The decoded call of a typed route: its path parameters and payload (JSON body or query),
shape-checked by the protocol’s
HttpCall::from_parts. A malformed body answers 400bad_request(or 413 / 415 likeApiJson), a bad path parameter 400 / 422. - Reply
- The answer of a typed route:
200with the call’s response as JSON, plus optional headers (e.g. anETag).
Traits§
- Call
Handler - A handler for the call
C: an async function whose LAST argument isCall<C>(any other extractors before it) and which returnsCallResult<C>. Implemented for such functions with up to eight extractors;Tis the tuple of the other extractors.
Functions§
- documented
handlermounted atC::ROUTEwith the OpenAPI operation ofdoc(the output ofutoipa_axum::routes!(handler); only its operation and schemas are used: the path and the method in the document are alwaysC’s). Usecall_route!.- method_
router - The method router of
handlerforC’s method; withC::ROUTE.auth, requests without an authenticated caller are answered 401 before the handler runs. A method this server version does not know mounts nothing (every request: 405; logged as an error;NetBackendServer::callrefuses it at build). - undocumented
handlermounted atC::ROUTEonrouter, without OpenAPI documentation.
Type Aliases§
- Call
Result - What a typed handler returns.