Created
March 27, 2023 22:08
-
-
Save timClicks/e5f7b855b4237dae2144a5dc69611818 to your computer and use it in GitHub Desktop.
Axum Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use axum::{response::Json, routing::get, Router}; | |
use serde_json::{json, Value}; | |
async fn greet() -> Json<Value> { | |
Json(json!({ "msg": "Hello, world!" })) | |
} | |
#[tokio::main] | |
async fn main() { | |
tracing_subscriber::fmt() | |
.with_max_level(tracing::Level::TRACE) | |
.init(); | |
let app = Router::new().route("/", get(greet)); | |
axum::Server::bind(&"0.0.0.0:8080".parse().unwrap()) | |
.serve(app.into_make_service()) | |
.await | |
.unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment