Prefer the repo Golden Path for the full story (OpenAPI path, probes, MCP/deploy forks).
This page is the CLI-generated project path.
cargo install cargo-rustapicargo rustapi new my-api
cd my-apiIf
cargo rustapidoes not work, runcargo-rustapi new my-apidirectly.
src/main.rs should look like:
use rustapi_rs::prelude::*;
#[rustapi_rs::get("/hello")]
async fn hello() -> Json<String> {
Json("Hello from RustAPI!".to_string())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tracing_subscriber::fmt::init();
RustApi::auto()
.production_defaults("my-api")
.run("127.0.0.1:8080")
.await
}For the minimal macro + probes example without the CLI, clone this monorepo and run:
cargo run -p rustapi-rs --example golden_pathcargo run- App:
curl http://127.0.0.1:8080/hello(or/api/v1/pingon golden_path) - Docs: http://127.0.0.1:8080/docs
- Spec:
http://127.0.0.1:8080/docs/openapi.json
- Automatic OpenAPI from route macros +
Schema - Swagger UI at
/docs - With
production_defaults: request IDs, tracing,/live/ready/health
Next: Golden Path · Installation · Structure