Claude Skills Guide

Claude Code Actix Web Rust API Guide

Actix Web remains one of the most performant web frameworks in the Rust ecosystem When combined with Claude Code’s AI capabilities, you can rapidly prototype, develop, and test REST APIs while using Rust’s memory safety guarantees. This guide covers building practical APIs using Claude Code sessions and relevant skills.

Setting Up Your Rust API Project

Initialize a new Actix Web project using Cargo:

cargo new rust-api-guide
cd rust-api-guide
cargo add actix-web tokio serde serde_json serde_derive
cargo add actix-rt --features macros

Configure your Cargo.toml dependencies:

[dependencies]
actix-web = "4"
actix-rt = "2"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Creating Your First Endpoint

Define a simple REST endpoint with request validation. Here’s a practical example of a user management endpoint:

// src/main.rs
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct User {
    id: u64,
    name: String,
    email: String,
}

#[derive(Deserialize)]
struct CreateUserRequest {
    name: String,
    email: String,
}

async fn get_users() -> impl Responder {
    let users = vec![
        User { id: 1, name: "Alice".to_string(), email: "alice@example.com".to_string() },
        User { id: 2, name: "Bob".to_string(), email: "bob@example.com".to_string() },
    ];
    HttpResponse::Ok().json(users)
}

async fn create_user(req: web::Json<CreateUserRequest>) -> impl Responder {
    let new_user = User {
        id: 3,
        name: req.name.clone(),
        email: req.email.clone(),
    };
    HttpResponse::Created().json(new_user)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .route("/users", web::get().to(get_users))
            .route("/users", web::post().to(create_user))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

Run the server with cargo run and test with curl:

curl http://127.0.0.1:8080/users
curl -X POST http://127.0.0.1:8080/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Charlie", "email": "charlie@example.com"}'

Using Claude Code with Your API

Activate Claude Code and use specific skills to enhance your development workflow. The /tdd skill helps generate unit tests for your endpoint handlers:

/tdd
Write tests for a create_user handler that validates email format and rejects empty names

The skill guides Claude to produce test cases covering validation logic, edge cases, and error responses.

For API documentation, use the /pdf skill to generate structured documentation from your OpenAPI specs or code comments:

/pdf
Generate API documentation from the OpenAPI spec in ./api-spec.yaml

Advanced: Database Integration with Diesel

Connect your Actix Web API to a PostgreSQL database using Diesel ORM:

// src/models.rs
use diesel::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Queryable, Serialize, Deserialize)]
pub struct User {
    pub id: i32,
    pub username: String,
    pub email: String,
}

#[derive(Insertable)]
#[table_name = "users"]
pub struct NewUser<'a> {
    pub username: &'a str,
    pub email: &'a,
}

Configure connection pooling in your main.rs:

use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;

type DbPool = Pool<ConnectionManager<PgConnection>>;

async fn get_all_users(pool: web::Data<DbPool>) -> impl Responder {
    use crate::schema::users::dsl::*;

    let conn = pool.get().unwrap();
    let results = users.load::<User>(&conn).unwrap();
    HttpResponse::Ok().json(results)
}

Error Handling Patterns

Implement consistent error responses across your API:

#[derive(Serialize)]
struct ApiError {
    code: String,
    message: String,
}

impl actix_web::ResponseError for ApiError {
    fn error_response(&self) -> HttpResponse {
        HttpResponse::BadRequest().json(self)
    }
}

Use this pattern with the /tdd skill to ensure your error paths are tested:

/tdd
Generate test cases for the create_user endpoint covering: valid input, missing name, invalid email format, database connection failure

Using supermemory for API Patterns

The /supermemory skill stores your preferred API patterns across sessions. Store common patterns:

/supermemory store: API error response format uses { "code": "ERROR_CODE", "message": "Human readable message" }. Standard pagination params are page and limit.

Claude remembers these patterns in future sessions, applying consistent designs across your API endpoints.

Combining Multiple Skills

For full-stack API development, combine skills effectively:

  1. Use /tdd to generate tests before implementing handlers
  2. Apply /frontend-design to build accompanying React/Vue components that consume your API
  3. Use /pdf to export API documentation for stakeholders
  4. Reference /supermemory to maintain consistent error formats and naming conventions

Example workflow:

/tdd
Write handler tests for a product inventory endpoint

/frontend-design
Scaffold a React component that displays inventory data with pagination

/pdf
Create API documentation from the spec

Conclusion

Claude Code accelerates Actix Web development by generating tests, documenting APIs, and maintaining consistent patterns across your codebase. The combination of Rust’s performance and AI-assisted development creates a productive workflow for building high-performance web services.

The key is invoking the right skill at the appropriate time: /tdd for test generation, /pdf for documentation, and /supermemory for pattern retention. Your Actix Web APIs benefit from both Rust’s compile-time safety and Claude’s development velocity.


Built by theluckystrike — More at zovo.one