Rust Axum REST API Builder

backend
Rust
scaffolding
strict_senior
Remix

Build a production-ready REST API using Axum framework with custom endpoints, database, and authentication.

12/8/2025

Prompt

Build a Rust REST API using Axum for the following requirements:

API Purpose and Scope

  • API Purpose: [e.g., User management system, E-commerce backend, Blog platform, IoT data aggregator]
  • Target Scale: [Small / Medium / High-traffic with load balancing]
  • Deployment Target: [Docker / Cloud native / Bare metal / Serverless]

Core Endpoints

Define your API endpoints (provide 4-8 endpoints):

Endpoint 1: [Name]

  • HTTP Method: [GET / POST / PUT / PATCH / DELETE]
  • Path: [e.g., /api/users, /api/products/:id]
  • Purpose: [What this endpoint does]
  • Authentication Required: [Yes / No]
  • Request Body Schema: [Field names and types if applicable]
  • Response Schema: [Expected response structure]

Endpoint 2: [Name]

  • HTTP Method: [GET / POST / PUT / PATCH / DELETE]
  • Path: [e.g., /api/auth/login]
  • Purpose: [What this endpoint does]
  • Authentication Required: [Yes / No]
  • Request Body Schema: [Field names and types if applicable]
  • Response Schema: [Expected response structure]

[Continue for 4-8 total endpoints]

Database Configuration

  • Database Type: [PostgreSQL / MySQL / SQLite / MongoDB / None]
  • ORM/Query Builder: [SQLx / Diesel / SeaORM / None]
  • Connection Pooling: [Yes with size: X / No]
  • Migrations: [Include migration setup / Manual / Not needed]
  • Database Models: [List main models: User, Product, Order, etc.]

Authentication & Security

  • Authentication Method: [JWT / Session-based / API Keys / OAuth2 / None]
  • Password Hashing: [bcrypt / argon2 / scrypt]
  • Token Storage: [Headers / Cookies / Both]
  • CORS Configuration: [Permissive / Restricted to domains: [LIST] / None]
  • Rate Limiting: [Required / Optional / None]

Middleware Requirements

  • Request Logging: [Structured logging with tracing / Simple logs / None]
  • Error Handling: [Custom error types / Simple / Standard]
  • Request Validation: [Strict with validator crate / Manual / Basic]
  • Compression: [gzip / brotli / None]

Project Structure

  • Preferred Organization: [Domain-driven / Feature-based / Layer-based]
  • Folder Structure: [routes/, handlers/, models/, services/ OR custom layout]

Additional Features

  • Health Check Endpoint: [Yes at /health / Custom path / No]
  • API Documentation: [OpenAPI/Swagger / README only / None]
  • Testing: [Unit tests / Integration tests / Both / None]
  • Background Jobs: [Tokio tasks / External queue / None]
  • File Uploads: [Required / Not needed]
  • WebSocket Support: [Required / Not needed]

Environment Configuration

  • Configuration Method: [.env file / config.toml / Environment variables]
  • Required Environment Variables: [List: DATABASE_URL, JWT_SECRET, etc.]

Error Response Format

  • Error Structure: [JSON with code and message / Simple string / Custom]
  • HTTP Status Codes: [RESTful standard / Custom mappings]

Generate a complete Rust Axum REST API with:

  • Full project structure with all necessary files
  • Cargo.toml with all required dependencies
  • Main application setup with router configuration
  • All endpoint handlers with proper request/response types
  • Database models and queries (if database is used)
  • Authentication middleware (if authentication is required)
  • Error handling types and implementations
  • CORS and other middleware configuration
  • Environment variable setup example

Output production-ready, idiomatic Rust code with proper error handling, type safety, and async/await patterns.

Tags

rust
axum
api
sqlx

Tested Models

gpt-4
claude-3-opus

Comments (0)

Sign in to leave a comment

Sign In
Rust Axum REST API Builder | vibeprompt.directory