Multiple file routing setup
This commit is contained in:
26
src/main.rs
Normal file
26
src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use axum::{
|
||||
//response::Html,
|
||||
routing::get, //post,
|
||||
Router
|
||||
};
|
||||
|
||||
mod routes;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
let app : Router = routes::create_routes();
|
||||
|
||||
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
||||
.await
|
||||
.unwrap();
|
||||
println!("listining on {}", listener.local_addr().unwrap() );
|
||||
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
async fn handler() -> &'static str {
|
||||
"Hiii from localhost"
|
||||
}
|
||||
15
src/routes/inventory.rs
Normal file
15
src/routes/inventory.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use axum::{
|
||||
routing::{get, //post
|
||||
},
|
||||
Router,
|
||||
};
|
||||
|
||||
pub fn inventory_routes() -> Router {
|
||||
|
||||
Router::new()
|
||||
.route("/", get(hi_inventory) )
|
||||
}
|
||||
|
||||
async fn hi_inventory() -> &'static str {
|
||||
"Hiii from inventory.rs route module"
|
||||
}
|
||||
12
src/routes/mod.rs
Normal file
12
src/routes/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use axum::{
|
||||
Router,
|
||||
};
|
||||
|
||||
pub mod rooms;
|
||||
pub mod inventory;
|
||||
|
||||
pub fn create_routes() -> Router {
|
||||
Router::new()
|
||||
.nest("/inventory", inventory::inventory_routes())
|
||||
.nest("/rooms", rooms::rooms_routes())
|
||||
}
|
||||
15
src/routes/rooms.rs
Normal file
15
src/routes/rooms.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use axum::{
|
||||
routing::{get, //post
|
||||
},
|
||||
Router,
|
||||
};
|
||||
|
||||
pub fn rooms_routes() -> Router {
|
||||
|
||||
Router::new()
|
||||
.route("/", get(hi_rooms) )
|
||||
}
|
||||
|
||||
async fn hi_rooms() -> &'static str {
|
||||
"Hiii from room.rs route module"
|
||||
}
|
||||
Reference in New Issue
Block a user