It's a basic template for creating Rust web servers and REST APIs, with containerization using Docker. This template outlines the steps to develop, containerize, and deploy a simple Rust web server that greets users via a RESTful endpoint.
- Rust Programming Language
- Cargo (Rust's package manager)
- Docker (for containerization)
-
Clone the Template: Start by cloning this template repository to set up the project environment. Ensure Rust and Cargo are installed on the local machine.
-
Local Server Execution: To run the server locally, navigate to the project's root directory in your terminal and execute:
cargo build --release cargo run --release
This command compiles the Rust application and initiates the server, defaulting to listen on
localhost:8080
.
Access the /greet
endpoint to receive a response from the API endpoint. Include a name
query parameter like so:
curl "http://localhost:8080/greet?name=NightFury"
Response:
Hello, NightFury, from Rust Server!
Image Creation: Generate a Docker image by running:
docker build -t simple-rust-server .
Deploy the application as a Docker container with:
docker run -d -p 8080:8080 simple-rust-server
To specify a custom port:
docker run -d -p <HostPort>:<ContainerPort> -e PORT=<ContainerPort> simple-rust-server
Replace <HostPort>
and <ContainerPort>
with a desired port numbers.
With the Docker container operational, the REST API is accessible as if the server were running locally. To greet someone, use:
curl "http://localhost:<Port>/greet?name=MrXYZ"
Ensure <Port>
matches the port configured when launching the Docker container.