ESC
Type to search...

Installation

Install Rapina and create your first API

Prerequisites

Rapina is a Rust framework, so you'll need Rust installed on your system. If you're new to Rust, don't worry — installation takes about a minute.

Installing Rust

The recommended way to install Rust is through rustup, the official Rust toolchain installer.

macOS / Linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After installation, restart your terminal or run:

source $HOME/.cargo/env

Windows:

Download and run rustup-init.exe from the official website. Follow the on-screen instructions.

Alternatively, if you use winget:

winget install Rustlang.Rustup

Verify Installation

Confirm Rust is installed correctly:

rustc --version
cargo --version

You should see version numbers for both. Rapina requires Rust 1.75 or later.

Platform Notes

macOS: Works out of the box. Xcode Command Line Tools will be installed automatically if needed.

Linux: You may need to install build essentials. On Ubuntu/Debian:

sudo apt install build-essential pkg-config libssl-dev

On Fedora:

sudo dnf install gcc pkg-config openssl-devel

Windows: Visual Studio Build Tools are required. The rustup installer will guide you through this. Make sure to select "Desktop development with C++" workload.

The fastest way to get started is with the Rapina CLI:

# Install the CLI
cargo install rapina-cli

# Create a new project
rapina new my-app
cd my-app

# Start the development server
rapina dev

Your API is now running at http://127.0.0.1:3000.

Manual Setup

Add Rapina to your Cargo.toml:

[dependencies]
rapina = "0.6.0"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }

Your First API

Create a simple API with a few endpoints:

use rapina::prelude::*;

#[get("/")]
async fn hello() -> &'static str {
    "Hello, Rapina!"
}

#[get("/users/:id")]
async fn get_user(id: Path<u64>) -> Result<Json<serde_json::Value>> {
    Ok(Json(serde_json::json!({
        "id": id.into_inner(),
        "name": "Alice"
    })))
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let router = Router::new()
        .get("/", hello)
        .get("/users/:id", get_user);

    Rapina::new()
        .router(router)
        .listen("127.0.0.1:3000")
        .await
}