handle all xrpc routes with NotImplemented
Supported routes can be added as they become available
This commit is contained in:
parent
1d577ef396
commit
57c396afe7
3 changed files with 20 additions and 11 deletions
2
rust/Cargo.lock
generated
2
rust/Cargo.lock
generated
|
|
@ -345,6 +345,8 @@ name = "rust"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -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"] }
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
use axum::{
|
||||
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>) -> String {
|
||||
nsid
|
||||
}
|
||||
|
||||
async fn xrpc_post(Path(nsid): Path<String>) -> String {
|
||||
nsid
|
||||
async fn not_implemented(Path(_nsid): Path<String>) -> (StatusCode, Json<Value>) {
|
||||
(
|
||||
StatusCode::NOT_IMPLEMENTED,
|
||||
Json(json!({
|
||||
"error": "MethodNotImplemented",
|
||||
"message": "Method Not Implemented"
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue