Created
February 19, 2024 00:30
-
-
Save mayankchoubey/d326fdaf230d07cb8dec8fe7583aba4e to your computer and use it in GitHub Desktop.
Rocket vs Actix vs Axum vs Warp vs Gotham
This file contains 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, App, HttpServer, Responder}; | |
use uuid::Uuid; | |
#[get("/")] | |
async fn index() -> impl Responder { | |
return "Hello ".to_owned() + &Uuid::new_v4().to_string(); | |
} | |
#[actix_web::main] | |
async fn main() -> std::io::Result<()> { | |
HttpServer::new(|| App::new().service(index)) | |
.bind(("127.0.0.1", 3000))? | |
.run() | |
.await | |
} |
This file contains 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 axum::{ | |
routing::get, | |
Router, | |
}; | |
use uuid::Uuid; | |
#[tokio::main] | |
async fn main() { | |
let app = Router::new().route("/", get(|| async { | |
"Hello ".to_owned() + &Uuid::new_v4().to_string() | |
})); | |
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000") | |
.await | |
.unwrap(); | |
axum::serve(listener, app).await.unwrap(); | |
} |
This file contains 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 gotham::prelude::*; | |
use gotham::router::{build_simple_router, Router}; | |
use gotham::state::State; | |
use uuid::Uuid; | |
pub fn say_hello(state: State) -> (State, String) { | |
(state, "Hello ".to_owned() + &Uuid::new_v4().to_string()) | |
} | |
fn router() -> Router { | |
build_simple_router(|route| { | |
route.get("/").to(say_hello); | |
}) | |
} | |
pub fn main() { | |
let addr = "127.0.0.1:3000"; | |
gotham::start(addr, router()).unwrap(); | |
} |
This file contains 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
#[macro_use] extern crate rocket; | |
use uuid::Uuid; | |
#[get("/")] | |
fn index() -> String { | |
return "Hello ".to_owned() + &Uuid::new_v4().to_string(); | |
} | |
#[launch] | |
fn rocket() -> _ { | |
rocket::build().mount("/", routes![index]) | |
} |
This file contains 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 warp::Filter; | |
use uuid::Uuid; | |
#[tokio::main] | |
async fn main() { | |
let routes = warp::path::end().map(|| | |
"Hello ".to_owned() + &Uuid::new_v4().to_string() | |
); | |
warp::serve(routes) | |
.run(([127, 0, 0, 1], 3000)) | |
.await; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment