Created
October 1, 2020 19:28
-
-
Save JoaoPedroPP/b79428a4cbc9556a9d5c42bf86fe7055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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