Create server with some endpoints

This commit is contained in:
2025-11-06 19:11:34 +03:00
parent cb006b52d5
commit 6eab539107
3 changed files with 674 additions and 2 deletions

View File

@ -1,3 +1,26 @@
fn main() {
println!("Hello, world!");
use axum::{
Router,
response::IntoResponse,
routing::{delete, get, post},
};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
let router = Router::new().nest(
"/sandwiches",
Router::new()
.route("/", get(handler))
.route("/", post(handler))
.route("/{id}", post(handler))
.route("/{id}", delete(handler)),
);
let addr = "0.0.0.0:8000";
let listener = TcpListener::bind(addr).await.unwrap();
println!("Listener at {addr}");
axum::serve(listener, router).await.unwrap();
}
async fn handler() -> impl IntoResponse {
axum::http::StatusCode::NOT_IMPLEMENTED
}