Skip to main content

Crate jacquard_axum

Crate jacquard_axum 

Source
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§

ExtractXrpc
Axum extractor for XRPC requests.
GenericXrpcErrorResponse
Axum-compatible generic XRPC error response.
XrpcErrorResponse
Axum-compatible typed XRPC error wrapper.
XrpcResponse
Typed axum response wrapper for XRPC endpoint outputs.

Traits§

IntoRouter
Conversion trait to turn an XRPC endpoint marker and a handler into a router.
XrpcExtractBacking
Backing-specific XRPC request extraction policy.