Bu proje, Java Spring Framework kullanılarak geliştirilmiş modern bir REST API uygulamasıdır. Spring Boot'un güçlü özelliklerini kullanarak, ölçeklenebilir ve sürdürülebilir bir backend servisi sunmayı amaçlamaktadır. RESTful API prensiplerine uygun olarak tasarlanmış ve modern web uygulamaları için güvenilir bir backend çözümü sağlar.
- RESTful API: HTTP standartlarına uygun REST endpoint'leri
- CRUD İşlemleri: Create, Read, Update, Delete operasyonları
- Veritabanı Entegrasyonu: JPA/Hibernate ile ORM desteği
- Güvenlik: Spring Security ile kimlik doğrulama ve yetkilendirme
- Validasyon: Bean Validation ile veri doğrulama
- Dokümantasyon: Swagger/OpenAPI ile API dokümantasyonu
- JWT Token: JSON Web Token tabanlı kimlik doğrulama
- Spring Security: Güvenlik katmanı ve yetkilendirme
- Password Encoding: BCrypt ile şifre hashleme
- CORS Yapılandırması: Cross-origin resource sharing desteği
- Rate Limiting: API istek sınırlama
- JPA/Hibernate: Object-Relational Mapping
- Repository Pattern: Veri erişim katmanı
- Transaction Management: İşlem yönetimi
- Database Migration: Flyway veya Liquibase ile veritabanı migrasyonu
- Connection Pooling: HikariCP ile bağlantı havuzu
- Actuator: Uygulama sağlığı ve metrikler
- Logging: SLF4J ve Logback ile loglama
- Health Checks: Uygulama durumu kontrolü
- Metrics: Prometheus metrikleri
- Tracing: Distributed tracing desteği
- Unit Testing: JUnit 5 ile birim testler
- Integration Testing: Spring Boot Test ile entegrasyon testleri
- Mock Testing: Mockito ile mock testler
- Code Coverage: JaCoCo ile kod kapsama raporu
- Static Analysis: SonarQube ile kod kalitesi analizi
- Spring Boot 3.x: Ana framework
- Spring Web: REST API desteği
- Spring Data JPA: Veritabanı erişimi
- Spring Security: Güvenlik katmanı
- Spring Validation: Veri doğrulama
- Hibernate: JPA implementasyonu
- H2 Database: Geliştirme veritabanı
- PostgreSQL/MySQL: Prodüksiyon veritabanı
- HikariCP: Bağlantı havuzu
- Spring Security: Güvenlik framework'ü
- JWT: JSON Web Token
- BCrypt: Şifre hashleme
- CORS: Cross-origin resource sharing
- Maven: Bağımlılık yönetimi
- Lombok: Boilerplate kod azaltma
- MapStruct: Object mapping
- Swagger/OpenAPI: API dokümantasyonu
- JUnit 5: Test framework'ü
- Mockito: Mock kütüphanesi
- TestContainers: Container tabanlı testler
- JaCoCo: Kod kapsama analizi
- Java 17 veya üzeri
- Maven 3.6+
- Git
- IDE (IntelliJ IDEA, Eclipse, VS Code)
git clone https://github.com/orhanurullah/java-spring-api.git
cd java-spring-api
# H2 Database (geliştirme için otomatik başlar)
# PostgreSQL için:
sudo -u postgres createdb spring_api_db
# Maven ile
mvn spring-boot:run
# Veya JAR dosyası oluşturup çalıştırın
mvn clean package
java -jar target/java-spring-api-1.0.0.jar
Uygulama http://localhost:8080
adresinde çalışmaya başlayacaktır.
java-spring-api/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/springapi/
│ │ │ ├── SpringApiApplication.java # Ana uygulama sınıfı
│ │ │ ├── config/ # Konfigürasyon sınıfları
│ │ │ │ ├── SecurityConfig.java
│ │ │ │ ├── SwaggerConfig.java
│ │ │ │ └── DatabaseConfig.java
│ │ │ ├── controller/ # REST Controller'ları
│ │ │ │ ├── UserController.java
│ │ │ │ ├── ProductController.java
│ │ │ │ └── AuthController.java
│ │ │ ├── service/ # İş mantığı katmanı
│ │ │ │ ├── UserService.java
│ │ │ │ ├── ProductService.java
│ │ │ │ └── AuthService.java
│ │ │ ├── repository/ # Veri erişim katmanı
│ │ │ │ ├── UserRepository.java
│ │ │ │ └── ProductRepository.java
│ │ │ ├── model/ # Entity sınıfları
│ │ │ │ ├── User.java
│ │ │ │ └── Product.java
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ │ ├── UserDto.java
│ │ │ │ └── ProductDto.java
│ │ │ ├── exception/ # Özel exception'lar
│ │ │ │ ├── ResourceNotFoundException.java
│ │ │ │ └── GlobalExceptionHandler.java
│ │ │ └── util/ # Yardımcı sınıflar
│ │ │ ├── JwtUtil.java
│ │ │ └── ResponseUtil.java
│ │ └── resources/
│ │ ├── application.yml # Uygulama konfigürasyonu
│ │ ├── application-dev.yml # Geliştirme konfigürasyonu
│ │ ├── application-prod.yml # Prodüksiyon konfigürasyonu
│ │ └── db/migration/ # Veritabanı migrasyon dosyaları
│ └── test/
│ └── java/
│ └── com/example/springapi/
│ ├── controller/ # Controller testleri
│ ├── service/ # Service testleri
│ └── repository/ # Repository testleri
├── pom.xml # Maven bağımlılıkları
├── .gitignore # Git ignore dosyası
└── README.md # Proje dokümantasyonu
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50),
role VARCHAR(20) DEFAULT 'USER',
enabled BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE products (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
category VARCHAR(50),
stock_quantity INT DEFAULT 0,
created_by BIGINT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id)
);
POST /api/auth/login # Kullanıcı girişi
POST /api/auth/register # Kullanıcı kaydı
POST /api/auth/refresh # Token yenileme
POST /api/auth/logout # Çıkış yapma
GET /api/users # Tüm kullanıcıları listele
GET /api/users/{id} # Kullanıcı detayı
POST /api/users # Yeni kullanıcı oluştur
PUT /api/users/{id} # Kullanıcı güncelle
DELETE /api/users/{id} # Kullanıcı sil
GET /api/products # Tüm ürünleri listele
GET /api/products/{id} # Ürün detayı
POST /api/products # Yeni ürün oluştur
PUT /api/products/{id} # Ürün güncelle
DELETE /api/products/{id} # Ürün sil
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "password123"
}'
curl -X GET http://localhost:8080/api/products \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
spring:
application:
name: java-spring-api
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
username: sa
password: password
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
properties:
hibernate:
format_sql: true
h2:
console:
enabled: true
path: /h2-console
server:
port: 8080
jwt:
secret: your-secret-key-here
expiration: 86400000 # 24 saat
logging:
level:
com.example.springapi: DEBUG
org.springframework.security: DEBUG
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/auth/**").permitAll()
.requestMatchers("/h2-console/**").permitAll()
.anyRequest().authenticated()
)
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
# Tüm testleri çalıştır
mvn test
# Belirli bir test sınıfını çalıştır
mvn test -Dtest=UserServiceTest
# Test coverage raporu
mvn jacoco:report
# Entegrasyon testlerini çalıştır
mvn test -Dtest=*IntegrationTest
# TestContainers ile test
mvn test -Dtest=*ContainerTest
# Postman Collection'ı import edin
# veya curl ile test edin
curl -X GET http://localhost:8080/api/health
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.5.3.Final</version>
</dependency>
FROM openjdk:17-jdk-slim
VOLUME /tmp
COPY target/java-spring-api-1.0.0.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
# Docker image oluştur
docker build -t java-spring-api .
# Container çalıştır
docker run -p 8080:8080 java-spring-api
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-spring-api
spec:
replicas: 3
selector:
matchLabels:
app: java-spring-api
template:
metadata:
labels:
app: java-spring-api
spec:
containers:
- name: java-spring-api
image: java-spring-api:latest
ports:
- containerPort: 8080
env:
- name: SPRING_PROFILES_ACTIVE
value: "prod"
# Heroku
heroku create java-spring-api
git push heroku main
# AWS Elastic Beanstalk
eb init java-spring-api
eb create production
eb deploy
GET /actuator/health # Uygulama sağlığı
GET /actuator/info # Uygulama bilgileri
GET /actuator/metrics # Metrikler
GET /actuator/env # Ortam değişkenleri
GET /actuator/loggers # Logger seviyeleri
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
metrics:
export:
prometheus:
enabled: true
- Bu repository'yi fork edin
- Yeni bir branch oluşturun (
git checkout -b feature/yeni-ozellik
) - Değişikliklerinizi commit edin (
git commit -am 'Yeni özellik eklendi'
) - Branch'inizi push edin (
git push origin feature/yeni-ozellik
) - Pull Request oluşturun
- Java kod standartlarına uyun
- Unit test yazın
- API dokümantasyonunu güncelleyin
- Commit mesajlarını açıklayıcı yazın
Bu proje MIT lisansı altında lisanslanmıştır. Detaylar için LICENSE
dosyasına bakın.
Herhangi bir sorun yaşarsanız:
- Issues bölümünde arama yapın
- Yeni bir issue oluşturun
- Detaylı hata açıklaması ve adımları ekleyin
Bu proje Orhan Urullah tarafından geliştirilmiştir.
- İlk sürüm yayınlandı
- Temel CRUD işlemleri
- JWT kimlik doğrulama
- Spring Security entegrasyonu
- Swagger dokümantasyonu
- GraphQL desteği
- WebSocket entegrasyonu
- Redis cache
- Elasticsearch entegrasyonu
- Microservices mimarisi
⭐ Bu projeyi beğendiyseniz yıldız vermeyi unutmayın!
- GitHub: @orhanurullah
- E-posta: orhanurullah@example.com
- LinkedIn: Orhan Urullah
Java Spring REST API - Modern backend çözümü 🚀