openbook-candles/server/src/main.rs

32 lines
707 B
Rust
Raw Normal View History

2023-03-05 23:11:15 -08:00
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, middleware::Logger};
#[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() -> anyhow::Result<()> {
HttpServer::new(|| {
App::new()
.wrap(Logger::default())
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
2023-03-05 22:52:42 -08:00
}