Expand description
§Axum helpers for jacquard XRPC server implementations.
§Usage.
This crate provides server-side helpers for wiring generated Jacquard XRPC
endpoint marker types into axum routers. ExtractXrpc decodes query
parameters or procedure bodies into owned request values, defaulting to
DefaultStr-backed generated types, and XrpcResponse encodes endpoint
outputs with the content type declared by the endpoint response marker.
use axum::Router;
use jacquard::api::com_atproto::identity::resolve_handle::{
ResolveHandleOutput, ResolveHandleRequest,
};
use jacquard::types::string::Did;
use jacquard_axum::{ExtractXrpc, IntoRouter, XrpcResponse};
use miette::{IntoDiagnostic, Result};
async fn handle_resolve(
ExtractXrpc(req): ExtractXrpc<ResolveHandleRequest>,
) -> XrpcResponse<ResolveHandleRequest> {
let _handle = req.handle;
XrpcResponse(ResolveHandleOutput {
did: Did::new_static("did:plc:test").unwrap(),
extra_data: None,
})
}
#[tokio::main]
async fn main() -> Result<()> {
let app = Router::new()
.route("/", axum::routing::get(|| async { "hello world!" }))
.merge(ResolveHandleRequest::into_router(handle_resolve));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
.await
.into_diagnostic()?;
axum::serve(listener, app).await.unwrap();
Ok(())
}The extractor uses the XrpcEndpoint trait to determine request type:
- Query endpoints deserialize from query string parameters.
- Procedure endpoints deserialize from request bodies and preserve custom
encodings through
XrpcRequest::decode_body.
Deserialization errors return a 400 Bad Request with a JSON body matching the XRPC error format.
Modules§
- did_web
- Helper for serving did:web DID documents
- oauth
- OAuth web helpers for Axum applications.
- service_
auth - Service authentication extractor and middleware.
Structs§
- Extract
Xrpc - Axum extractor for XRPC requests.
- Generic
Xrpc Error Response - Axum-compatible generic XRPC error response.
- Xrpc
Error Response - Axum-compatible typed XRPC error wrapper.
- Xrpc
Response - Typed axum response wrapper for XRPC endpoint outputs.
Traits§
- Into
Router - Conversion trait to turn an XRPC endpoint marker and a handler into a router.
- Xrpc
Extract Backing - Backing-specific XRPC request extraction policy.