Skip to content

A high-performance, modern blog backend API built with Rust, Axum and SQLx. Features automatic database migrations, comprehensive testing, and Docker containerization.

License

Notifications You must be signed in to change notification settings

sw3do/BlogAppBackend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Blog App Backend

Rust Axum MySQL Docker

CI/CD License GitHub issues GitHub stars

A high-performance, modern blog backend API built with Rust, Axum, and SQLx. Features automatic database migrations, comprehensive testing, and Docker containerization.

✨ Features

  • πŸš€ High Performance - Built with Rust and Axum for maximum speed
  • πŸ—„οΈ Database Migrations - Automatic SQLx migrations with version control
  • πŸ”’ Type Safety - Compile-time guarantees with Rust's type system
  • 🐳 Containerized - Docker support for easy deployment
  • πŸ§ͺ Well Tested - Comprehensive test suite with CI/CD
  • πŸ“Š RESTful API - Clean, documented REST endpoints
  • 🏷️ Tag System - JSON-based tagging with search capabilities
  • πŸ“ Rich Content - Support for markdown content and excerpts
  • πŸ” Search & Filter - Full-text search and tag filtering
  • ⚑ CORS Enabled - Ready for frontend integration

πŸ› οΈ Tech Stack

  • Language: Rust πŸ¦€
  • Web Framework: Axum
  • Database: MySQL 8.0
  • ORM: SQLx with compile-time checked queries
  • Serialization: Serde
  • Async Runtime: Tokio
  • Containerization: Docker & Docker Compose
  • CI/CD: GitHub Actions

πŸš€ Quick Start

Prerequisites

🐳 Docker Setup (Recommended)

  1. Clone the repository:

    git clone https://github.com/sw3do/BlogAppBackend.git
    cd BlogAppBackend
  2. Create environment file:

    cp .env.example .env
    # Edit .env with your configuration
  3. Start with Docker Compose:

    docker-compose up -d
  4. Access the API:

πŸ”§ Local Development Setup

  1. Install dependencies:

    # Install SQLx CLI
    cargo install sqlx-cli --no-default-features --features native-tls,mysql
  2. Setup database:

    # Create database
    sqlx database create
    
    # Run migrations
    ./migrate.sh run
  3. Run the application:

    cargo run

πŸ“š API Documentation

Base URL

http://localhost:3000/api

Endpoints

Method Endpoint Description
GET /posts Get published posts with pagination
GET /posts/:slug Get post by slug
POST /posts Create new post
GET /admin/posts Get all posts (admin)
GET /admin/posts/:id Get post by ID
PUT /admin/posts/:id Update post
DELETE /admin/posts/:id Delete post
GET /config Get site configuration
GET /health Health check

Query Parameters

GET /posts

  • page - Page number (default: 1)
  • limit - Posts per page (default: 10, max: 50)
  • tag - Filter by tag
  • search - Search in title and content

Example Requests

Get posts with pagination:

curl "http://localhost:3000/api/posts?page=1&limit=5"

Search posts:

curl "http://localhost:3000/api/posts?search=rust&tag=programming"

Create a post:

curl -X POST "http://localhost:3000/api/posts" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My First Post",
    "content": "This is the content...",
    "excerpt": "A brief excerpt",
    "slug": "my-first-post",
    "author": "sw3do",
    "published": true,
    "tags": ["rust", "programming"]
  }'

πŸ—„οΈ Database Schema

See migrations/README.md for detailed database schema documentation.

πŸ§ͺ Testing

# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test test_name

πŸš€ Deployment

Docker Deployment

  1. Build production image:

    docker build -t blog-backend .
  2. Run with environment variables:

    docker run -d \
      --name blog-backend \
      -p 3000:3000 \
      -e DATABASE_URL="mysql://user:pass@host:3306/db" \
      blog-backend

GitHub Container Registry

Images are automatically built and pushed to GitHub Container Registry:

docker pull ghcr.io/sw3do/blog-backend:latest

πŸ”§ Configuration

Environment variables:

Variable Description Default
DATABASE_URL MySQL connection string Required
SERVER_HOST Server bind address 127.0.0.1
SERVER_PORT Server port 3000
SITE_NAME Blog site name My Blog
SITE_DESCRIPTION Site description A beautiful blog
SITE_URL Site URL http://localhost:4321
SITE_AUTHOR Default author Blog Author
POSTS_PER_PAGE Default pagination 10
RUST_LOG Log level info

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Rust naming conventions
  • Add tests for new features
  • Update documentation
  • Ensure CI passes
  • Use conventional commits

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

sw3do

πŸ™ Acknowledgments

  • Axum - Amazing web framework
  • SQLx - Async SQL toolkit
  • Tokio - Async runtime
  • Serde - Serialization framework

⭐ Star this repository if you find it helpful!

About

A high-performance, modern blog backend API built with Rust, Axum and SQLx. Features automatic database migrations, comprehensive testing, and Docker containerization.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •