A simple FastAPI application with token authentication that returns a greeting message. The purpose of this repo is to be used for a Challenge.
- Token-based authentication using an API key
- Environment variable configuration for token and message
- Docker and Docker Compose support
- Health check endpoint
The application uses two environment variables:
API_TOKEN: A secret token that clients must provide for authenticationMESSAGE: The greeting message to return (defaults to "World" if not provided)
- Clone this repository
- (Optional) Edit the
docker-compose.ymlfile to set your ownAPI_TOKENandMESSAGEvalues - Run the application:
docker-compose up -d# Build the Docker image
docker build -t fastapi-hello .
# Run the container
docker run -p 8000:8000 -e API_TOKEN=your_secret_token -e MESSAGE=YourName fastapi-hello- Install the dependencies:
pip install -r requirements.txt- Set the environment variables:
export API_TOKEN=your_secret_token
export MESSAGE=YourName- Run the application:
uvicorn app:app --reloadGET /: Returns a greeting message. Requires authentication.GET /health: Health check endpoint. Does not require authentication.
To authenticate, include the API token in the X-API-Key header:
X-API-Key: your_secret_token
curl -X GET "http://localhost:8000/" -H "X-API-Key: your_secret_token_here"Expected response:
{"message": "Hello, FastAPI"}