Skip to content

Instantly share code, notes, and snippets.

@JoaoPedroPP
Created October 1, 2020 19:28
Show Gist options
  • Save JoaoPedroPP/b79428a4cbc9556a9d5c42bf86fe7055 to your computer and use it in GitHub Desktop.
Save JoaoPedroPP/b79428a4cbc9556a9d5c42bf86fe7055 to your computer and use it in GitHub Desktop.
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment