Compare commits
No commits in common. "v6" and "main" have entirely different histories.
@ -1,2 +1,2 @@
|
||||
# 46cb9cb30fd348309af0f6c232b41057
|
||||
# b67fd3e848314c79947fe878ce916df5
|
||||
|
||||
|
||||
36
main.rs
36
main.rs
@ -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();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user