# Spring Boot Application for Hugging Face Spaces A simple Spring Boot REST API application designed to be deployed on Hugging Face Spaces. ## Features - REST API with multiple endpoints - Health check endpoint for monitoring - Containerized with Docker - Configured for Hugging Face Spaces deployment (port 7860) ## API Endpoints ### GET /api/ Returns a welcome message with current status. **Response:** ```json { "message": "Welcome to Spring Boot on Hugging Face!", "status": "running", "timestamp": "2024-11-13T10:30:00" } ``` ### GET /api/greeting Returns a personalized greeting. **Parameters:** - `name` (optional): Name for the greeting (default: "World") **Example:** `/api/greeting?name=John` **Response:** ```json { "greeting": "Hello, John!", "timestamp": "2024-11-13T10:30:00" } ``` ### GET /api/health Health check endpoint. **Response:** ```json { "status": "UP", "service": "Spring Boot Demo" } ``` ### POST /api/echo Echoes back the received JSON payload. **Request Body:** ```json { "message": "test", "data": "example" } ``` **Response:** ```json { "received": { "message": "test", "data": "example" }, "timestamp": "2024-11-13T10:30:00" } ``` ## Local Development ### Prerequisites - Java 17 or higher - Maven 3.6 or higher ### Running Locally 1. Clone the repository 2. Navigate to the project directory 3. Run the application: ```bash mvn spring-boot:run ``` 4. Access the application at `http://localhost:7860/api/` ### Building the JAR ```bash mvn clean package ``` ### Running with Docker ```bash # Build the Docker image docker build -t springboot-hf-demo . # Run the container docker run -p 7860:7860 springboot-hf-demo ``` ## Deploying to Hugging Face Spaces 1. Create a new Space on Hugging Face 2. Choose "Docker" as the SDK 3. Upload these files to your Space repository: - `Dockerfile` - `pom.xml` - `src/` directory with all Java files and resources - `README.md` 4. The Space will automatically build and deploy your application ### Hugging Face Configuration The application is configured to: - Listen on port 7860 (required by Hugging Face) - Bind to all network interfaces (0.0.0.0) - Run as a non-root user for security ## Project Structure ``` springboot-app/ ├── src/ │ └── main/ │ ├── java/ │ │ └── com/example/demo/ │ │ ├── DemoApplication.java │ │ └── controller/ │ │ └── GreetingController.java │ └── resources/ │ └── application.properties ├── Dockerfile ├── pom.xml └── README.md ``` ## Technologies Used - Spring Boot 3.2.1 - Java 17 - Maven - Docker - Spring Web - Spring Boot Actuator ## License This project is open source and available for educational purposes. ## Contributing Feel free to fork this project and customize it for your needs!