Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-test-

- name: Run tests
run: cargo test --workspace

- name: Run tests with all features
run: cargo test --workspace --all-features

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-lint-

- name: Check formatting
run: cargo fmt --all -- --check

- name: Run clippy
run: cargo clippy --workspace --all-features -- -D warnings

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-

- name: Build
run: cargo build --workspace

- name: Build with all features
run: cargo build --workspace --all-features

- name: Build release
run: cargo build --workspace --release

docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-docs-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-docs-

- name: Build documentation
run: cargo doc --workspace --all-features --no-deps
env:
RUSTDOCFLAGS: -D warnings

msrv:
name: MSRV (1.75)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust 1.75
uses: dtolnay/rust-action@1.75

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-msrv-

- name: Check MSRV
run: cargo check --workspace --all-features
89 changes: 89 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.2] - 2024-12-31

### Added
- `skip_paths` method for JwtLayer to exclude paths from JWT validation
- `docs_with_auth` method for Basic Auth protected Swagger UI
- `docs_with_auth_and_info` method for customized protected docs

### Changed
- auth-api example now demonstrates protected docs with Basic Auth
- JWT middleware can now skip validation for public endpoints

## [0.1.1] - 2024-12-31

### Added

#### Phase 4: Ergonomics & v1.0 Preparation
- Body size limit middleware with configurable limits
- `.body_limit(size)` builder method on RustApi (default: 1MB)
- 413 Payload Too Large response for oversized requests
- Production error masking (`RUSTAPI_ENV=production`)
- Development error details (`RUSTAPI_ENV=development`)
- Unique error IDs (`err_{uuid}`) for log correlation
- Enhanced tracing layer with request_id, status, and duration
- Custom span field support via `.with_field(key, value)`
- Prometheus metrics middleware (feature-gated)
- `http_requests_total` counter with method, path, status labels
- `http_request_duration_seconds` histogram
- `rustapi_info` gauge with version information
- `/metrics` endpoint handler
- TestClient for integration testing without network binding
- TestRequest builder with method, header, and body support
- TestResponse with assertion helpers
- `RUSTAPI_DEBUG=1` macro expansion output support
- Improved route path validation at compile time
- Enhanced route conflict detection messages

### Changed
- Error responses now include `error_id` field
- TracingLayer enhanced with additional span fields

## [0.1.0] - 2024-12-01

### Added

#### Phase 1: MVP Core
- Core HTTP server built on tokio and hyper 1.0
- Radix-tree based routing with matchit
- Request extractors: `Json<T>`, `Query<T>`, `Path<T>`
- Response types with automatic serialization
- Async handler support
- Basic error handling with `ApiError`
- `#[rustapi::get]`, `#[rustapi::post]` route macros
- `#[rustapi::main]` async main macro

#### Phase 2: Validation & OpenAPI
- Automatic OpenAPI spec generation
- Swagger UI at `/docs` endpoint
- Request validation with validator crate
- `#[validate]` attribute support
- 422 Unprocessable Entity for validation errors
- `#[rustapi::tag]` and `#[rustapi::summary]` macros
- Schema derivation for request/response types

#### Phase 3: Batteries Included
- JWT authentication middleware (`jwt` feature)
- `AuthUser<T>` extractor for authenticated routes
- CORS middleware with builder pattern (`cors` feature)
- IP-based rate limiting (`rate-limit` feature)
- Configuration management with `.env` support (`config` feature)
- Cookie parsing extractor (`cookies` feature)
- SQLx error conversion (`sqlx` feature)
- Request ID middleware
- Middleware layer trait for custom middleware
- `extras` meta-feature for common optional features
- `full` feature for all optional features

[Unreleased]: https://github.com/Tuntii/RustAPI/compare/v0.1.2...HEAD
[0.1.2]: https://github.com/Tuntii/RustAPI/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/Tuntii/RustAPI/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/Tuntii/RustAPI/releases/tag/v0.1.0
141 changes: 141 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Contributing to RustAPI

Thank you for your interest in contributing to RustAPI! This document provides guidelines and information for contributors.

## Code of Conduct

By participating in this project, you agree to maintain a respectful and inclusive environment for everyone.

## Getting Started

1. Fork the repository
2. Clone your fork: `git clone https://github.com/Tuntii/RustAPI.git`
3. Create a new branch: `git checkout -b feature/your-feature-name`
4. Make your changes
5. Run tests: `cargo test --workspace`
6. Submit a pull request

## Development Setup

### Prerequisites

- Rust 1.75 or later
- Cargo (comes with Rust)

### Building

```bash
# Build all crates
cargo build --workspace

# Build with all features
cargo build --workspace --all-features
```

### Running Tests

```bash
# Run all tests
cargo test --workspace

# Run tests with all features
cargo test --workspace --all-features

# Run a specific crate's tests
cargo test -p rustapi-core
```

## Code Style

### Formatting

All code must be formatted with `rustfmt`:

```bash
cargo fmt --all
```

### Linting

All code must pass `clippy` checks:

```bash
cargo clippy --workspace --all-features -- -D warnings
```

### Documentation

- All public APIs must have rustdoc documentation
- Include code examples in doc comments where appropriate
- Doc examples must compile and run

## Pull Request Process

1. **Create a descriptive PR title** following conventional commits:
- `feat:` for new features
- `fix:` for bug fixes
- `docs:` for documentation changes
- `refactor:` for code refactoring
- `test:` for test additions/changes
- `chore:` for maintenance tasks

2. **Fill out the PR template** with:
- Description of changes
- Related issue numbers
- Testing performed

3. **Ensure all checks pass**:
- All tests pass
- Code is formatted (`cargo fmt`)
- No clippy warnings (`cargo clippy`)
- Documentation builds

4. **Request review** from maintainers

5. **Address feedback** promptly and push updates

## Commit Guidelines

- Write clear, concise commit messages
- Use present tense ("Add feature" not "Added feature")
- Reference issues when applicable (`Fixes #123`)

## Project Structure

```
RustAPI/
├── crates/
│ ├── rustapi-rs/ # Public-facing crate (re-exports)
│ ├── rustapi-core/ # Core HTTP engine and routing
│ ├── rustapi-macros/ # Procedural macros
│ ├── rustapi-validate/ # Validation integration
│ ├── rustapi-openapi/ # OpenAPI/Swagger support
│ └── rustapi-extras/ # Optional features (JWT, CORS, etc.)
├── examples/ # Example applications
├── benches/ # Benchmarks
└── scripts/ # Build and publish scripts
```

## Adding New Features

1. Discuss the feature in an issue first
2. Follow the existing architecture patterns
3. Add tests for new functionality
4. Update documentation
5. Add examples if applicable

## Reporting Issues

When reporting issues, please include:

- Rust version (`rustc --version`)
- RustAPI version
- Minimal reproduction code
- Expected vs actual behavior
- Error messages (if any)

## Questions?

Feel free to open an issue for questions or join discussions in existing issues.

Thank you for contributing to RustAPI!
Loading
Loading