Compare commits

..

No commits in common. "v5" and "main" have entirely different histories.
v5 ... main

2 changed files with 1 additions and 37 deletions

View File

@ -1,2 +1,2 @@
# 46cb9cb30fd348309af0f6c232b41057 # 690c5c49a9cf415e8f67a80ad3e79185

36
main.rs
View File

@ -1,36 +0,0 @@
use axum::{Router, routing::get, Json};
use serde::Serialize;
use std::net::SocketAddr;
use tokio::net::TcpListener;
#[derive(Serialize)]
struct Variables {
user_name: String,
age: i32,
is_student: bool,
score: f32,
}
async fn display_variables() -> Json<Variables> {
// Declare and assign variables of different types
let user_name = String::from("Alice");
let age = 25;
let is_student = true;
let score = 95.5;
// Return variables as JSON
Json(Variables {
user_name,
age,
is_student,
score,
})
}
#[tokio::main]
async fn main() {
// Create Axum router with a single route
let router = Router::new().route("/variables", get(display_variables));
// Set up server address and port
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
let tcp = TcpListener::bind(&addr).await.unwrap();
println!("Ready and listening on {}", addr);
// Start the server
axum::serve(tcp, router).await.unwrap();
}