diff --git a/Cargo.lock b/Cargo.lock index dd2ff6b6..a4e9e15d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,6 +632,9 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", "sync_wrapper", "tokio", "tower", @@ -692,7 +695,7 @@ dependencies = [ name = "axum-example" version = "0.1.0" dependencies = [ - "axum 0.6.20", + "axum 0.7.2", "serde", "surrealdb", "thiserror", diff --git a/lib/examples/axum/Cargo.toml b/lib/examples/axum/Cargo.toml index 99f00ae5..a90c965c 100644 --- a/lib/examples/axum/Cargo.toml +++ b/lib/examples/axum/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies] -axum = "0.6.20" +axum = "0.7.2" serde = { version = "1.0.193", features = ["derive"] } surrealdb = { path = "../.." } thiserror = "1.0.50" diff --git a/lib/examples/axum/src/main.rs b/lib/examples/axum/src/main.rs index 617f0541..d22ce8b2 100644 --- a/lib/examples/axum/src/main.rs +++ b/lib/examples/axum/src/main.rs @@ -2,11 +2,11 @@ mod error; mod person; use axum::routing::{delete, get, post, put}; -use axum::{Router, Server}; -use std::net::SocketAddr; +use axum::Router; use surrealdb::engine::remote::ws::Ws; use surrealdb::opt::auth::Root; use surrealdb::Surreal; +use tokio::net::TcpListener; #[tokio::main] async fn main() -> Result<(), Box> { @@ -20,7 +20,7 @@ async fn main() -> Result<(), Box> { db.use_ns("namespace").use_db("database").await?; - let app = Router::new() + let router = Router::new() .route("/person/:id", post(person::create)) .route("/person/:id", get(person::read)) .route("/person/:id", put(person::update)) @@ -28,9 +28,9 @@ async fn main() -> Result<(), Box> { .route("/people", get(person::list)) .with_state(db); - let addr = SocketAddr::from(([127, 0, 0, 1], 8080)); + let listener = TcpListener::bind("localhost:8080").await?; - Server::bind(&addr).serve(app.into_make_service()).await?; + axum::serve(listener, router).await?; Ok(()) }