Last active
April 28, 2023 14:39
-
-
Save SaltyAom/febba890744f8f777b8aa37f6fe62845 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
// @see https://github.com/SaltyAom/bun-http-framework-benchmark | |
use actix_web::{ HttpServer, App, get, post, web::{ Path, Query, Json }, HttpResponse }; | |
use serde::{Deserialize, Serialize}; | |
#[derive(Deserialize)] | |
struct QueryParams { | |
name: String | |
} | |
#[derive(Serialize, Deserialize)] | |
struct IncomingBody { | |
hello: String | |
} | |
#[get("/")] | |
async fn index() -> &'static str { | |
"hi" | |
} | |
#[get("/id/{id}")] | |
async fn params(path: Path<String>, query: Query<QueryParams>) -> HttpResponse { | |
HttpResponse::Ok() | |
.append_header(("x-powered-by", "benchmark")) | |
.body(format!("{} {}", path, query.name)) | |
} | |
#[post("/json")] | |
async fn mirror(body: Json<IncomingBody>) -> Json<IncomingBody> { | |
body | |
} | |
#[actix_web::main] | |
async fn main() -> std::io::Result<()> { | |
HttpServer::new(|| { | |
App::new() | |
.service(index) | |
.service(params) | |
.service(mirror) | |
}) | |
.bind(("0.0.0.0", 3000))? | |
.run() | |
.await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment