From 57c396afe7295d3afabe009148495814e9218866 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 18 Apr 2025 19:10:17 -0700 Subject: [PATCH] handle all xrpc routes with NotImplemented Supported routes can be added as they become available --- rust/Cargo.lock | 2 ++ rust/Cargo.toml | 4 +++- rust/src/router.rs | 25 +++++++++++++++---------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 898f3f9..a2cd918 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -345,6 +345,8 @@ name = "rust" version = "0.1.0" dependencies = [ "axum", + "serde", + "serde_json", "tokio", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ac1838d..46be5f3 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -6,5 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axum = "0.8.3" +axum = { version = "0.8.3", features = ["json"] } +serde = "1.0.219" +serde_json = "1.0.140" tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] } diff --git a/rust/src/router.rs b/rust/src/router.rs index ce18fa6..e571f7f 100644 --- a/rust/src/router.rs +++ b/rust/src/router.rs @@ -1,22 +1,27 @@ use axum::{ - routing::get, - extract::Path, - Router, + Json, + routing::get, + extract::Path, + http::StatusCode, + Router, }; +use serde_json::{Value, json}; use tokio::net::TcpListener; pub async fn setup() { let app = Router::new() - .route("/xrpc/{nsid}", get(xrpc_get).post(xrpc_post)); + .route("/xrpc/{*nsid}", get(not_implemented).post(not_implemented)); let listener = TcpListener::bind("0.0.0.0:6702").await.unwrap(); axum::serve(listener, app).await.unwrap(); } -async fn xrpc_get(Path(nsid): Path) -> String { - nsid -} - -async fn xrpc_post(Path(nsid): Path) -> String { - nsid +async fn not_implemented(Path(_nsid): Path) -> (StatusCode, Json) { + ( + StatusCode::NOT_IMPLEMENTED, + Json(json!({ + "error": "MethodNotImplemented", + "message": "Method Not Implemented" + })) + ) }