A sample Actix Web application demonstrating integration with ClickHouse using the klickhouse library. This example covers essential aspects of building a web service in Rust, including routing, middleware, and database connectivity.
-
Actix Web
- Route handling (e.g.,
GET
,POST
) - Custom middleware for logging and error handling
- Route handling (e.g.,
-
ClickHouse Integration
- Reading from and writing to ClickHouse
- Example table (
web_server_logs
) to store and retrieve logs
-
Logging Middleware
- Captures HTTP request/response details and saves them into ClickHouse
-
Error & Panic Handling
- Demonstrates capturing errors and panics within the Actix Web middleware stack
- Devenv - https://devenv.sh/ (for running the application under development environment)
-
Clone the repository:
git clone https://github.com/your-org/klickhouse-example.git cd klickhouse-example
-
Run the application:
direnv allow devenv up // for running clickhouse as a service cargo run migrate // to run clickhouse migrations cargo run serve // to run web the server
-
Access the application:
- Open your browser and navigate to
http://localhost:1337/health
to check if the application is running. - Open your browser and navigate to
http://localhost:1337/logs?limit=10&offset=0
to view the logs.
- Open your browser and navigate to
-
Run tests + all rust checks:
// cargo test/fmt/clippy/audit/outdated just // only tests just test
Endpoint | Method | Description | Example |
---|---|---|---|
/ |
GET | Demo endpoint with request ID | curl http://localhost:1337 |
/health |
GET | Healthcheck | curl http://localhost:1337/health |
/logs |
GET | Get paginated logs | curl "http://localhost:1337/logs?limit=5&offset=0" |
/fail |
GET | Trigger handle panic example | curl http://localhost:1337/fail |
cargo run migrate
: Run ClickHouse migrations.cargo run serve
: Run the web server.
confik.toml
: Configuration file for the application..env
: Environment variables for the application (optional).
# x86_64
docker build -t klickhouse-example .
# ARM64
docker build -t klickhouse-example -f aarch64.Dockerfile .
Feel free to open issues or PRs to improve this example — whether adding features or refining best practices. All suggestions are welcome!
This project is open-sourced under the MIT License - see the LICENSE file for details.