Quickstart
Tip
From zero to a production-ready API in 60 seconds.
Install the CLI
First, install the RustAPI CLI tool:
cargo install cargo-rustapi
Create a New Project
Use the CLI to generate a new project. We’ll call it my-api.
cargo rustapi new my-api
cd my-api
Note: If
cargo rustapidoesn’t work, you can also runcargo-rustapi new my-apidirectly.
This command sets up a complete project structure with handling, models, and tests ready to go.
The Code
Open src/main.rs. You’ll see how simple it is:
use rustapi_rs::prelude::*;
#[rustapi_rs::get("/hello")]
async fn hello() -> Json<String> {
Json("Hello from RustAPI!".to_string())
}
#[rustapi_rs::main]
async fn main() -> Result<()> {
// Auto-discovery magic ✨
RustApi::auto()
.run("127.0.0.1:8080")
.await
}
Run the Server
Start your API server:
cargo run
You should see output similar to:
INFO rustapi: 🚀 Server running at http://127.0.0.1:8080
INFO rustapi: 📚 API docs at http://127.0.0.1:8080/docs
Test It Out
Open your browser to http://127.0.0.1:8080/docs.
You’ll see the Swagger UI automatically generated from your code. Try out the endpoint directly from the browser!
What Just Happened?
You just launched a high-performance, async Rust web server with:
- ✅ Automatic OpenAPI documentation
- ✅ Type-safe request validation
- ✅ Distributed tracing
- ✅ Global error handling
Welcome to RustAPI.