This is a simple Vapor-based API that serves a single endpoint to return a greeting message with environment variables. This is the base code used in following posts Customizing Vapor Server Configurations
- Implements a single endpoint
/hello - Reads values from environment variables
- Returns a greeting message including a secret value
- Swift (latest stable version)
- Vapor 4
- Docker (optional, for containerized deployment)
- Clone the repository:
git clone https://github.com/your-username/your-repo.git cd your-repo - Install dependencies:
swift package resolve
- Set up environment variables:
export CUSTOM_VARIABLE="YourName" export SECRET="YourSecretValue"
- Run the application:
swift run
Description: Returns a greeting message including the secret value.
Response:
"Hello, YourName! secret is YourSecretValue"To deploy using Docker:
- Build the Docker image:
docker build -t vapor-app . - Run the container:
docker run -p 8080: