Skip to content

Instantly share code, notes, and snippets.

@SaltyAom
Last active April 28, 2023 14:39
Show Gist options
  • Save SaltyAom/febba890744f8f777b8aa37f6fe62845 to your computer and use it in GitHub Desktop.
Save SaltyAom/febba890744f8f777b8aa37f6fe62845 to your computer and use it in GitHub Desktop.
// @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