Search
 
SCRIPT & CODE EXAMPLE
 

RUST

actix web

use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello World")
}

// remains post, patch, put, delete etc requests


#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(hello))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}
Comment

actix web

use actix_web::{web, App, HttpRequest, HttpServer, Responder};

async fn greet(req: HttpRequest) -> impl Responder {
    let name = req.match_info().get("name").unwrap_or("World");
    format!("Hello {}!", &name)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to(greet))
            .route("/{name}", web::get().to(greet))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}
Comment

actix web

#[derive(Serialize)]
struct Measurement {
    temperature: f32,
}

async fn hello_world() -> impl Responder {
    "Hello World!"
}

async fn current_temperature() -> impl Responder {
    web::Json(Measurement { temperature: 42.3 })
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rust file extension 
Rust :: length of vector rust 
Rust :: rust error handling 
Rust :: calculator in rust 
Rust :: use module within another module rust 
Rust :: const generics in rust 
Rust :: rust concat 
Rust :: tcp listener rust 
Rust :: create a new rust project folder with cargo 
Rust :: does rust support classes 
Rust :: armanriazi•rust•thread•strateges 
Rust :: armanriazi•rust•interior-mutability•vs•inherited-mutability 
Rust :: rust•armanriazi•lifetime•unsafe•destructor 
Rust :: armanriazi•rust•error•E0220•associated type `` not found for `Self` 
Rust :: armanriazi•rust•stack•vs•heap 
Rust :: rust get items in a list 
Rust :: blank struct rust 
Rust :: rust compiler error 
Lua :: roblox make rainbow part 
Lua :: luau how to make region3 
Lua :: roblox on touch script 
Lua :: roblox table.find() 
Lua :: roblox rotate model 
Lua :: roblox number generator 
Lua :: lua insert table into table 
Lua :: Roblox Luau Wait Alternative 
Lua :: lua random numbers printing 
Lua :: convert a float to string lua 
Lua :: How to use Humanoids in Roblox Lua 
Matlab :: matlab root finding function 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =