Upgrade Axum example to Axum 0.7.2 (#3172)
Co-authored-by: Rushmore Mushambi <rushmore@surrealdb.com>
This commit is contained in:
parent
7bd958300a
commit
d4cc3272da
3 changed files with 10 additions and 7 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -632,6 +632,9 @@ dependencies = [
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_path_to_error",
|
||||||
|
"serde_urlencoded",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
|
@ -692,7 +695,7 @@ dependencies = [
|
||||||
name = "axum-example"
|
name = "axum-example"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum 0.6.20",
|
"axum 0.7.2",
|
||||||
"serde",
|
"serde",
|
||||||
"surrealdb",
|
"surrealdb",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = "0.6.20"
|
axum = "0.7.2"
|
||||||
serde = { version = "1.0.193", features = ["derive"] }
|
serde = { version = "1.0.193", features = ["derive"] }
|
||||||
surrealdb = { path = "../.." }
|
surrealdb = { path = "../.." }
|
||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
|
|
|
@ -2,11 +2,11 @@ mod error;
|
||||||
mod person;
|
mod person;
|
||||||
|
|
||||||
use axum::routing::{delete, get, post, put};
|
use axum::routing::{delete, get, post, put};
|
||||||
use axum::{Router, Server};
|
use axum::Router;
|
||||||
use std::net::SocketAddr;
|
|
||||||
use surrealdb::engine::remote::ws::Ws;
|
use surrealdb::engine::remote::ws::Ws;
|
||||||
use surrealdb::opt::auth::Root;
|
use surrealdb::opt::auth::Root;
|
||||||
use surrealdb::Surreal;
|
use surrealdb::Surreal;
|
||||||
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
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?;
|
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", post(person::create))
|
||||||
.route("/person/:id", get(person::read))
|
.route("/person/:id", get(person::read))
|
||||||
.route("/person/:id", put(person::update))
|
.route("/person/:id", put(person::update))
|
||||||
|
@ -28,9 +28,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.route("/people", get(person::list))
|
.route("/people", get(person::list))
|
||||||
.with_state(db);
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue