Sign inSign up

sushantjadhav/backend-api

By sushantjadhav

โ€ขUpdated about 1 year ago

Lightweight Flask API with health monitoring endpoints for microservices and containerized deploymnt

Image
Languages & frameworks
0

562

sushantjadhav/backend-api repository overview

โ 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:

  1. API Endpoints: Main API endpoint for testing connectivity
  2. Health Checks: Health monitoring endpoint for service status
  3. Status Monitoring: Status endpoint for service running state
  4. 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

  1. Build the image:

    docker build -t backend-service .
    
  2. Run the container:

    docker run -p 8080:8080 backend-service
    
  3. Test the API:

    curl http://localhost:8080/
    
โ Development Mode
  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Run the application:

    python app.py
    
  3. Test endpoints:

    curl http://localhost:8080/
    curl http://localhost:8080/api/healthcheck
    curl http://localhost:8080/api/status
    

โ ๐Ÿ“ Project Structure

backend/
โ”œโ”€โ”€ app.py                  # Main Flask application
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ Dockerfile             # Container definition
โ””โ”€โ”€ README.md              # This file

โ ๐Ÿ”ง 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"
}
โ GET /api/healthcheck

Description: Health check endpoint Response:

{
  "message": "Backend is healthy | called Healthcheck API Endpoint"
}
โ GET /api/status

Description: Status check endpoint Response:

{
  "message": "Backend is running | called Status API Endpoint"
}

โ ๐Ÿณ 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
  1. Base Setup: Python 3.11 Slim image
  2. Dependencies: Install from requirements.txt
  3. Application: Copy application code
  4. 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
  1. Build the Docker image
  2. Configure environment variables
  3. Deploy using container orchestration
  4. 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
  1. Add route in app.py:

    @app.route("/api/new-endpoint", methods=["GET"])
    def new_endpoint():
        return jsonify({"message": "New endpoint response"})
    
  2. Test the endpoint:

    curl http://localhost:8080/api/new-endpoint
    
โ 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
โ Integration Testing
  • Test with frontend service
  • Verify JSON response format
  • Check health check functionality

โ ๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

โ ๐Ÿ“ License

This project is open source and available under the MIT Licenseโ .

โ ๐Ÿ†˜ Support

For issues and questions:

  1. Check Flask application logs
  2. Verify port configuration
  3. Check Docker container status
  4. Review network connectivity

Built with โค๏ธ using Python, Flask, and Docker

Tag summary

Content type

Image

Digest

sha256:786050193โ€ฆ

Size

46.9 MB

Last updated

about 1 year ago

docker pull sushantjadhav/backend-api