โ Backend Service - API Testing Backend
A lightweight Python Flask backend service that provides RESTful API endpoints for testing and monitoring. This service serves as the backend for the multi-container API testing application.
โ ๐ Features
RESTful API : Clean REST endpoints for testing and monitoring
Health Monitoring : Built-in health check and status endpoints
JSON Responses : Consistent JSON response format
Docker Support : Containerized service with optimized build
Lightweight : Minimal dependencies for fast startup
Production Ready : Configured for production deployment
โ ๐ฏ What This Service Does
This backend service provides:
API Endpoints : Main API endpoint for testing connectivity
Health Checks : Health monitoring endpoint for service status
Status Monitoring : Status endpoint for service running state
JSON Responses : Structured JSON responses for frontend consumption
โ Available Endpoints:
GET / - Main API endpoint (returns welcome message)
GET /api/healthcheck - Health check endpoint
GET /api/status - Status check endpoint
โ ๐ ๏ธ Technology Stack
Runtime : Python 3.11
Framework : Flask
Dependencies : Flask, Requests
Containerization : Docker
Package Manager : pip
โ ๐ Quick Start
โ Using Docker (Recommended)
Build the image:
docker build -t backend-service .
Copy
Run the container:
docker run -p 8080:8080 backend-service
Copy
Test the API:
curl http://localhost:8080/
Copy
โ Development Mode
Install dependencies:
pip install -r requirements.txt
Copy
Run the application:
Test endpoints:
curl http://localhost:8080/
curl http://localhost:8080/api/healthcheck
curl http://localhost:8080/api/status
Copy
โ ๐ Project Structure
backend/
โโโ app.py # Main Flask application
โโโ requirements.txt # Python dependencies
โโโ Dockerfile # Container definition
โโโ README.md # This file
Copy
โ ๐ง Configuration
โ Environment Variables
FLASK_ENV: Flask environment (default: production)
PORT: Server port (default: 8080)
โ Dependencies
flask==2.3.3 - Web framework
requests==2.31.0 - HTTP library for health checks
โ ๐ API Documentation
โ Endpoints
โ GET /
Description : Main API endpoint
Response :
{
"message": "Hello from Backend!.... you are connected to the backend"
}
Copy
โ GET /api/healthcheck
Description : Health check endpoint
Response :
{
"message": "Backend is healthy | called Healthcheck API Endpoint"
}
Copy
โ GET /api/status
Description : Status check endpoint
Response :
{
"message": "Backend is running | called Status API Endpoint"
}
Copy
โ ๐ณ Docker Details
โ Image Specifications
Base Image : Python 3.11 Slim (lightweight)
Port : 8080 (configurable)
Size : Optimized with minimal dependencies
Dependencies : Production-only packages
โ Build Process
Base Setup : Python 3.11 Slim image
Dependencies : Install from requirements.txt
Application : Copy application code
Result : Minimal production image
โ ๐ Health Checks
The service includes built-in health check capabilities:
Internal Health Check : Flask application health
External Health Check : Can check external services
Status Monitoring : Service running status
Docker Health Check : Container-level health monitoring
โ ๐ Deployment
โ Production Deployment
Build the Docker image
Configure environment variables
Deploy using container orchestration
Set up load balancer if needed
โ Scaling
Stateless design allows horizontal scaling
Multiple instances can run simultaneously
Load balancer can distribute traffic
โ ๐ Performance
Fast Startup : Minimal dependencies for quick container startup
Low Memory : Lightweight Flask application
Efficient : Single-threaded but can be scaled horizontally
Reliable : Simple, focused functionality
โ ๐ง Development
โ Adding New Endpoints
Add route in app.py:
@app.route("/api/new-endpoint", methods=["GET"])
def new_endpoint():
return jsonify({"message": "New endpoint response"})
Copy
Test the endpoint:
curl http://localhost:8080/api/new-endpoint
Copy
โ Error Handling
The service includes basic error handling:
404 Errors : Automatic Flask 404 responses
500 Errors : Internal server error handling
JSON Responses : Consistent JSON error format
โ ๐งช Testing
โ Manual Testing
# Test main endpoint
curl http://localhost:8080/
# Test health check
curl http://localhost:8080/api/healthcheck
# Test status
curl http://localhost:8080/api/status
Copy
โ Integration Testing
Test with frontend service
Verify JSON response format
Check health check functionality
โ ๐ค Contributing
Fork the repository
Create a feature branch
Make your changes
Test thoroughly
Submit a pull request
โ ๐ License
This project is open source and available under the MIT Licenseโ .
โ ๐ Support
For issues and questions:
Check Flask application logs
Verify port configuration
Check Docker container status
Review network connectivity
Built with โค๏ธ using Python, Flask, and Docker