Skip to content

Instantly share code, notes, and snippets.

@timClicks
Created March 27, 2023 22:08
Show Gist options
  • Save timClicks/e5f7b855b4237dae2144a5dc69611818 to your computer and use it in GitHub Desktop.
Save timClicks/e5f7b855b4237dae2144a5dc69611818 to your computer and use it in GitHub Desktop.
Axum Example
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