A high-performance, modern blog backend API built with Rust, Axum, and SQLx. Features automatic database migrations, comprehensive testing, and Docker containerization.
- π 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
- 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
-
Clone the repository:
git clone https://github.com/sw3do/BlogAppBackend.git cd BlogAppBackend
-
Create environment file:
cp .env.example .env # Edit .env with your configuration
-
Start with Docker Compose:
docker-compose up -d
-
Access the API:
- API: http://localhost:3000
- Health Check: http://localhost:3000/health
- phpMyAdmin: http://localhost:8080
-
Install dependencies:
# Install SQLx CLI cargo install sqlx-cli --no-default-features --features native-tls,mysql
-
Setup database:
# Create database sqlx database create # Run migrations ./migrate.sh run
-
Run the application:
cargo run
http://localhost:3000/api
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 |
GET /posts
page
- Page number (default: 1)limit
- Posts per page (default: 10, max: 50)tag
- Filter by tagsearch
- Search in title and content
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"]
}'
See migrations/README.md for detailed database schema documentation.
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_name
-
Build production image:
docker build -t blog-backend .
-
Run with environment variables:
docker run -d \ --name blog-backend \ -p 3000:3000 \ -e DATABASE_URL="mysql://user:pass@host:3306/db" \ blog-backend
Images are automatically built and pushed to GitHub Container Registry:
docker pull ghcr.io/sw3do/blog-backend:latest
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 |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow Rust naming conventions
- Add tests for new features
- Update documentation
- Ensure CI passes
- Use conventional commits
This project is licensed under the MIT License - see the LICENSE file for details.
sw3do
- GitHub: @sw3do
- Website: sw3do.is-a.dev
- Axum - Amazing web framework
- SQLx - Async SQL toolkit
- Tokio - Async runtime
- Serde - Serialization framework
β Star this repository if you find it helpful!