Add axum server
This commit is contained in:
32
src/main.rs
32
src/main.rs
@ -1,3 +1,31 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use axum::{extract::Query, response::IntoResponse, routing::delete, routing::get, routing::post};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
async fn games_list() -> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
async fn add_game() -> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
async fn insert_game() -> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
async fn delete_game() -> impl IntoResponse {
|
||||
axum::http::StatusCode::NOT_IMPLEMENTED
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let router = axum::Router::new()
|
||||
.route("/api/games", get(games_list))
|
||||
.route("/api/games", post(add_game))
|
||||
.route("/api/games{id}", post(insert_game))
|
||||
.route("/api/games", delete(delete_game));
|
||||
let addr = "127.0.0.1:8000";
|
||||
let listener = TcpListener::bind(addr).await.unwrap();
|
||||
println!("listening at {addr}");
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user