Upgrade Axum example to Axum 0.7.2 (#3172)

Co-authored-by: Rushmore Mushambi <rushmore@surrealdb.com>
This commit is contained in:
Flint6872 2023-12-18 04:53:25 -08:00 committed by GitHub
parent 7bd958300a
commit d4cc3272da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

5
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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<dyn std::error::Error>> {
@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
.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(())
}