Skip to content

API REST example using DDD structure, unit test, custom exceptions, rest controller advice, stream api, api docs with swagger and custom interceptor to obtain a detailed log of the application's requests and responses.

Notifications You must be signed in to change notification settings

jsalonl/api-crud-interceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Springboot Custom Interceptor

github spring maven junit postgresql

Description

API CRUD example using:

  • DDD structure
  • Custom exceptions
  • Rest controller advice
  • Api docs with swagger
  • Custom interceptor to obtain a detailed log of the application's requests and responses.
  • Unit test (JUnit5 + Mockito)
  • Sonarqube analysis
  • Postman collection

Requirements

  • Java 11
  • Maven 3.6.3
  • Postgresql 13.2 (You can use another database, but you must change the dependencies in pom.xml)
  • Postman (Optional)
  • Sonarqube (Optional)
  • Intellij Idea (Optional)
  • Lombok (Recommended)

Structure of project

.
├──  domain                 # Business layer
     ├──  dto               # DTO
     ├──  service           # Logic layer
          ├──  impl         # Implementation of service
├──  exception		    # Handle custom exception
     ├──  controller	    # Rest Controller Advice
     ├──  dto		    # Custom DTO
├──  interceptor            # Custom Interceptor
     ├── dto         	    # Logger DTO for custom interceptor
     ├── service            # Service to log trace for custom interceptor
├──  persistence            # Data access
     ├──  entity            # Entities used in app
     ├──  mapper            # Mapper entities to DTO
          ├──  impl         # Implementation of mappers
     ├──  repository        # Repositories (JPA, CrudRepository, etc)
├──  util                   # Constants, formatters, etc
├──  web                    # REST Controller
├── dto                     # DTO example (Request and Response)
├── interceptor             # Interceptor config
    ├── dto         	    # Logger DTO
    ├── service             # Service to log trace
├── web			    # Rest Controller
├── postman                 # Folder to save  collection post

How to use

  1. Clone repository.
  2. Open folder.
  3. In folder src/main/resources it's located SQL file for this app
  4. Run:
    mvn clean && mvn install
    
  5. Open in your favorite IDE (I use Intellij Idea).
  6. Use postman to test (Collection included in postman folder).
  7. The endpoint is (http://localhost:8010/api-crud/v1/)[http://localhost:8010/api-crud/v1/]
  8. Documentation of API is in (http://localhost:8010/api-crud/v1/swagger-ui.html)[http://localhost:8010/api-crud/swagger-ui.html]

Screenshots

Swagger

Swagger

Swagger

LOG with custom interceptor is enabled

Log

Sonarqube analysis

Sonar

TODO

  • Make archetype in maven to facilitate implementation

Do you want to support me?

Buy Me A Coffee

About

API REST example using DDD structure, unit test, custom exceptions, rest controller advice, stream api, api docs with swagger and custom interceptor to obtain a detailed log of the application's requests and responses.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages