A modern, production-ready REST API built with Spring Boot for seamless
contact form submission handling.
Designed for reliability, validation, and scalability in real-world
backend systems.
- RESTful API design
- Input validation using Jakarta Validation
- Layered architecture (Controller → Service → Repository)
- JPA integration (MySQL / H2)
- Docker & Docker Compose support
- Environment-based configuration (dev / prod)
- Logging & structured error handling
- Production-ready security configuration
- Java 17+
- Spring Boot
- Spring Data JPA
- MySQL / H2
- Lombok
- JUnit 5 & Mockito
- Docker
./mvnw clean package./mvnw spring-boot:runThe API will be available at:
http://localhost:8080
docker build -t contact-form-api .docker run -p 8080:8080 contact-form-apiCreate a docker-compose.yml file:
version: '3.8'
services:
contact-form-api:
build: .
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prod
restart: unless-stoppedRun:
docker-compose up -dPOST /api/contact
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"subject": "Inquiry",
"message": "Your message here"
}{
"id": "123",
"status": "received",
"timestamp": "2026-03-01T10:30:00Z"
}{
"status": 400,
"message": "Validation failed",
"errors": [
{
"field": "email",
"message": "Invalid email format"
}
]
}GET /api/contact/{id}
{
"id": "123",
"name": "John Doe",
"email": "john@example.com",
"subject": "Inquiry",
"message": "Your message here",
"status": "received",
"createdAt": "2026-03-01T10:30:00Z"
}GET /api/contact?page=0&size=10
{
"content": [
{
"id": "123",
"name": "John Doe",
"email": "john@example.com",
"subject": "Inquiry",
"status": "received",
"createdAt": "2026-03-01T10:30:00Z"
}
],
"totalElements": 1,
"totalPages": 1,
"currentPage": 0
}contact-form-api/
├── src/
│ ├── main/
│ │ ├── java/com/mathalama/contactform/
│ │ │ ├── controller/
│ │ │ ├── service/
│ │ │ ├── model/
│ │ │ ├── repository/
│ │ │ ├── exception/
│ │ │ └── ContactFormApiApplication.java
│ │ └── resources/
│ │ ├── application.properties
│ │ ├── application-dev.properties
│ │ └── application-prod.properties
│ └── test/
├── pom.xml
├── Dockerfile
└── README.md
Includes:
- Server configuration
- Database connection
- Logging configuration
- Jackson settings
- CORS settings
Profiles:
- dev -- verbose logging & SQL output
- prod -- optimized for production (SSL enabled)
Run with profile:
./mvnw spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=dev"./mvnw test./mvnw spotless:check
./mvnw spotless:apply./mvnw javadoc:javadoc./mvnw clean package -DskipTests
java -jar target/contact-form-api-1.0.0.jar- Input validation on all endpoints
- Parameterized queries (SQL injection prevention)
- CORS configuration
- HTTPS-ready production profile
- Environment-based secrets
- CSRF protection
- Rate limiting support
Example Security Configuration:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.cors()
.and()
.authorizeRequests()
.antMatchers("/api/contact").permitAll()
.anyRequest().authenticated();
return http.build();
}
}- Email notification integration
- Full JPA persistence layer
- Admin dashboard
- Analytics & reporting
- Multi-language support
- WebSocket real-time updates
- OAuth2 authentication
- Scheduled batch processing
- Export (PDF / CSV)
- Automated response templates
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature - Commit changes
git commit -m "Add amazing feature" - Push to branch
git push origin feature/amazing-feature - Open a Pull Request
Ensure:
- Tests pass
- Code style is consistent
- Documentation is updated
MIT License. See LICENSE for details.
Built with precision by mathalama