Java API Generator is a tool that automates the creation of Java APIs using Spring Boot, Freemarker templates, and AI-driven code generation.
With this tool, you can:
✅ Generate a Java Controller automatically from an entity name.
✅ Create a complete Java class from a text prompt using AI.
✅ Build a fully functional API, packaged in a ZIP file, ready to run.
- Java 21 (Records, String Templates, Pattern Matching)
- Spring Boot 3 (Backend and API structure)
- Freemarker (Template engine for dynamic code generation)
- Mistral AI (via Hugging Face API for AI-powered class generation)
- Swagger/OpenAPI (for API documentation and testing)
git clone https://github.com/sbrunomello/java-api-generator.git
cd java-api-generator
Create a .env
file in the root directory and configure your Hugging Face API key:
AI_API_URL=https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct
AI_API_KEY=your_huggingface_api_key
Make sure you have Java 21+ installed, then execute:
./mvnw spring-boot:run
Once the application is running, access Swagger UI to test the endpoints:
📌 http://localhost:8080/swagger-ui.html
Endpoint: POST /api/generator/generate
Params:
packageName
(e.g.,"com.example"
)entityName
(e.g.,"User"
)
📌 Example Request:
curl -X POST "http://localhost:8080/api/generator/generate?packageName=com.example&entityName=User"
Endpoint: POST /api/generator/generate-ai
Params:
className
(e.g.,"OrderService"
)prompt
(e.g.,"Create a service class to manage orders"
)
📌 Example Request:
curl -X POST "http://localhost:8080/api/generator/generate-ai?className=OrderService&prompt=Create+a+service+class+to+manage+orders"
Endpoint: GET /api/generator/simple-api
Params:
projectName
(e.g.,"MyProject"
)packageName
(e.g.,"com.example"
)
📌 Example Request:
curl -X GET "http://localhost:8080/api/generator/simple-api?projectName=MyProject&packageName=com.example"
This will return a ZIP file containing a fully structured Spring Boot API project.
🚀 Build a front-end in Angular for better usability.
🚀 Integrate AI-powered class generation into complete API creation.
🚀 Replace cloud-based AI with a local AI model, making code generation faster, more secure, and fully independent.
Pull requests are welcome! If you’d like to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m "Add new feature"
). - Push the branch (
git push origin feature-branch
). - Open a Pull Request.