https://github.com/night-fury-me/smiple-rust-server
https://github.com/night-fury-me/smiple-rust-server
restful-api rust
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/night-fury-me/smiple-rust-server
- Owner: night-fury-me
- Created: 2024-03-02T07:26:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-02T07:45:02.000Z (over 1 year ago)
- Last Synced: 2025-01-16T10:37:19.118Z (5 months ago)
- Topics: restful-api, rust
- Language: Dockerfile
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A simple Rust web-server template
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.
## Requirements
- Rust Programming Language
- Cargo (Rust's package manager)
- Docker (for containerization)## Development Setup
1. **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.2. **Local Server Execution:**
To run the server locally, navigate to the project's root directory in your terminal and execute:```sh
cargo build --release
cargo run --release
```This command compiles the Rust application and initiates the server, defaulting to listen on `localhost:8080`.
## REST API Usage
Access the `/greet` endpoint to receive a response from the API endpoint. Include a `name` query parameter like so:
```sh
curl "http://localhost:8080/greet?name=NightFury"
```Response:
```
Hello, NightFury, from Rust Server!
```## Dockerization Guide
### Building a Docker Image
**Image Creation:**
Generate a Docker image by running:```sh
docker build -t simple-rust-server .
```### Running the Docker Container
Deploy the application as a Docker container with:
```sh
docker run -d -p 8080:8080 simple-rust-server
```To specify a custom port:
```sh
docker run -d -p : -e PORT= simple-rust-server
```Replace `` and `` with a desired port numbers.
## API Access via Docker
With the Docker container operational, the REST API is accessible as if the server were running locally. To greet someone, use:
```sh
curl "http://localhost:/greet?name=MrXYZ"
```Ensure `` matches the port configured when launching the Docker container.