API REST complète pour la gestion d'un refuge animal, construite avec Spring Boot. Ce projet inclut l'authentification JWT, le cryptage des mots de passe avec BCrypt, la documentation Swagger, et un CRUD complet pour les animaux.
- Java 21
- Spring Boot 4.0.2
- Spring Security + JWT (jjwt)
- Spring Data JPA + Hibernate
- MySQL (via WAMP)
- Swagger / SpringDoc OpenAPI
- BCrypt pour le hashage des mots de passe
- Maven
com.fadel.refugeapi/
├── config/
│ ├── SecurityConfig.java # Configuration Spring Security
│ ├── JwtFilter.java # Filtre JWT pour les requêtes
│ └── SwaggerConfig.java # Configuration Swagger/OpenAPI
├── controller/
│ ├── AuthController.java # Endpoints d'authentification
│ └── AnimalController.java # Endpoints CRUD animaux
├── dto/
│ ├── AnimalRequestDTO.java # DTO requête animal
│ ├── AnimalResponseDTO.java # DTO réponse animal
│ ├── RegisterDTO.java # DTO inscription
│ ├── LoginDTO.java # DTO connexion
│ └── AuthResponseDTO.java # DTO réponse auth (token)
├── entity/
│ ├── Animal.java # Entité Animal (JPA)
│ └── User.java # Entité User (JPA)
├── mapper/
│ └── AnimalMapper.java # Conversion DTO <-> Entity
├── repository/
│ ├── AnimalRepository.java # Repository Animal (JPA)
│ └── UserRepository.java # Repository User (JPA)
├── service/
│ ├── AnimalService.java # Logique métier animaux
│ ├── AuthService.java # Logique métier authentification
│ └── JwtService.java # Génération et validation JWT
└── RefugeApiApplication.java # Point d'entrée
| Méthode | URL | Description | Auth requise |
|---|---|---|---|
| POST | /api/auth/register |
Inscription | Non |
| POST | /api/auth/login |
Connexion | Non |
| Méthode | URL | Description | Auth requise |
|---|---|---|---|
| GET | /api/animaux |
Liste tous les animaux | Non |
| GET | /api/animaux/{id} |
Récupère un animal par ID | Non |
| POST | /api/animaux |
Créer un animal | Oui (JWT) |
| PUT | /api/animaux/{id} |
Modifier un animal | Oui (JWT) |
| DELETE | /api/animaux/{id} |
Supprimer un animal | Oui (JWT) |
| URL | Description |
|---|---|
/swagger-ui.html |
Interface Swagger interactive |
/v3/api-docs |
Documentation OpenAPI JSON |
- Java 21
- Maven
- MySQL (WAMP, XAMPP, ou autre)
- Cloner le dépôt
git clone https://github.com/fadel233/refuge-api.git
cd refuge-api- Créer la base de données MySQL
CREATE DATABASE refugedb;- Configurer la connexion dans
src/main/resources/application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/refugedb
spring.datasource.username=root
spring.datasource.password=- Lancer l'application
./mvnw spring-boot:run- Accéder à l'API
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "fadel@email.com",
"password": "monMotDePasse",
"nom": "Fadel"
}'curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "fadel@email.com",
"password": "monMotDePasse"
}'curl -X POST http://localhost:8080/api/animaux \
-H "Content-Type: application/json" \
-H "Authorization: Bearer VOTRE_TOKEN_JWT" \
-d '{
"nom": "Rex",
"type": "Chien",
"age": 5,
"poids": 25.0
}'curl http://localhost:8080/api/animaux- Les mots de passe sont hashés avec BCrypt
- L'authentification utilise des tokens JWT
- Les endpoints GET sont publics
- Les endpoints POST, PUT, DELETE nécessitent un token JWT valide
- Le token expire après 24 heures