This project provides a template for building a scalable HTTP server using Rust. It includes essential components such as an HTTP server, Docker support, and a CI pipeline setup with GitHub Actions.
- HTTP Server: Built using the Axum framework for high performance.
- Docker & Docker Compose: Ready-to-use Docker configurations for containerization.
- CI Pipeline: GitHub Actions setup for continuous integration and deployment.
- Rust: Ensure you have Rust installed. You can install it from rust-lang.org.
- Docker: Install Docker from docker.com.
- GitHub Actions: No setup required on your local machine; configuration files are included in the repository.
src/main.rs: Entry point for the application.src/env/: Handles environment variable parsing. And handles structure for application state.src/routes/: Defines application routes.src/utils/: Utility functions.**/__tests__/: Tests for the application.Dockerfile: Docker image definition.docker-compose.yml: Docker Compose configuration for development and production..github/workflows/ci.yml: GitHub Actions configuration for CI pipeline.
-
Clone the repository:
git clone https://github.com/marshallku/http_server_template.git cd http_server_template -
Set up environment variables: Create a
.envfile (or copy.env.exampleto.env) at the project root and define the necessary environment variables. For example:HOST=127.0.0.1 PORT=18080
-
Run the application locally:
cargo run
The server will start at the address defined in your environment variables (default:
http://127.0.0.1:18080).
To build and run the application using Docker:
-
Build the Docker image:
docker build -t rust-http-server-template . -
Run the container:
docker run -p 18080:18080 rust-http-server-template
Alternatively, use Docker Compose for easier management:
docker compose up
The project includes a GitHub Actions workflow for CI. It performs the following steps:
- Spell Check: Checks for spelling errors in source code.
- Build: Compiles the Rust project.
- Test: Runs unit and integration tests.
The workflow is defined in .github/workflows/ci.yml. It triggers on every push and pull request to the master branch.
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
This project is licensed under the MIT License. See the LICENSE file for more details.