FastAPI server that logs data and generates unique tokens associated with user-provided information.
551
This Docker image provides a FastAPI server that logs data and generates unique tokens associated with user-provided information. It also includes endpoints for querying the logs and tokens in both JSON and HTML formats. The image is built using Python and FastAPI, and it requires an API key for authorization.
log.txt file.tokens.txt..env file or passed as an environment variable during Docker run.POST /log: Logs incoming JSON data (email, message) into log.txt with timestamp.POST /token-new: Generates a new 4-digit alphanumeric token and stores it with the associated data in tokens.txt.GET /token-query: Queries a token and returns its associated data.GET /token-email: Returns the most recent token for a given email.GET /tokens: Displays all tokens in an HTML table.GET /logs: Displays all logs in an HTML table.GET /help: Returns usage instructions for the available endpoints.Clone the repository or ensure you have all the files (Dockerfile, main.py, requirements.txt) and run the following command to build the image:
docker build -t schogini/fastapi-token-logger .
To run the container, you need to pass the API key via an environment variable. The server will start on port 8000.
docker run --rm -e API_KEY="your-api-key" -p 8000:8000 schogini/fastapi-token-logger
Replace "your-api-key" with your actual API key.
Once the container is running, you can access the API documentation at:
http://localhost:8000/docs
This provides interactive documentation for all available endpoints.
/log)curl -X POST "http://localhost:8000/log" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "message": "Test log message"}'
/token-new)curl -X POST "http://localhost:8000/token-new" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "message": "Generate token"}'
/token-query)curl -X GET "http://localhost:8000/token-query?token=1234" \
-H "x-api-key: your-api-key"
/tokens)curl -X GET "http://localhost:8000/tokens?api_key=your-api-key"
/logs)curl -X GET "http://localhost:8000/logs?api_key=your-api-key"
.env file or pass it as an environment variable when running the Docker container.If you want to run the FastAPI server locally without Docker, you can set up a Python environment and install the dependencies from requirements.txt:
pip install -r requirements.txt
Then, you can run the FastAPI server with Uvicorn:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
You can pull the pre-built image from Docker Hub using:
docker pull schogini/fastapi-token-logger
This project is licensed under the MIT License.
This Docker image was created by Schogini Systems Private Limited. We specialize in AI Chatbot and Automation solutions for small businesses.
For more information about our services, visit: https://www.schogini.com.
Content type
Image
Digest
sha256:bf89c6a1d…
Size
51.3 MB
Last updated
almost 2 years ago
docker pull schogini/voiceflow-token-logger