Skip to content

MartinGiner9/RestForge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestForge

RestForge is a comprehensive Java library framework for Spring Boot 4.x that provides generic REST API functionality with minimal boilerplate code.

Features

  • Generic CRUD Operations: Base entities, services, and controllers for rapid API development
  • Optimistic Locking: Built-in versioning with @Version annotation
  • DTO Pattern: Automatic entity-DTO mapping with MapStruct
  • Pagination Support: Built-in pagination for all REST endpoints
  • Exception Handling: Global exception handler with standardized error responses
  • Auditing: Automatic creation and modification timestamps
  • Auto-Configuration: Spring Boot starter for easy integration
  • OpenAPI/Swagger: Automatic API documentation

Architecture

RestForge is a multi-module Maven project:

  • restforge-core: Core components (entities, services, controllers, DTOs, exception handling)
  • restforge-spring-boot-starter: Spring Boot auto-configuration

Requirements

  • Java 21 LTS
  • Spring Boot 4.0.0+
  • Maven 3.6+

Quick Start

1. Add RestForge to your project

<dependency>
    <groupId>io.mginer</groupId>
    <artifactId>restforge-spring-boot-starter</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

2. Create your entity

@Entity
public class Task extends BaseEntity<Long> {
    private String title;
    private String description;
    // getters and setters
}

3. Create your DTO

public class TaskDTO extends BaseDTO<Long> {
    private String title;
    private String description;
    // getters and setters
}

4. Create your mapper

@Mapper(componentModel = "spring")
public interface TaskMapper extends BaseMapper<Task, TaskDTO, Long> {
}

5. Create your service

@Service
public class TaskService extends BaseServiceImpl<Task, TaskDTO, Long> {
    private final TaskRepository repository;
    private final TaskMapper mapper;

    public TaskService(TaskRepository repository, TaskMapper mapper) {
        super(repository, mapper, "Task");
        this.repository = repository;
        this.mapper = mapper;
    }

    // Override methods if you need custom behavior
}

6. Create your controller

@RestController
@RequestMapping("/api/tasks")
public class TaskController extends BaseController<TaskDTO, Long> {
    private final TaskService service;

    public TaskController(TaskService service) {
        this.service = service;
    }

    @Override
    protected BaseService<?, TaskDTO, Long> getService() {
        return service;
    }
}

Building

mvn clean install

Testing

mvn test

Configuration

RestForge can be configured via application.properties:

# Enable/disable global exception handler
restforge.enable-global-exception-handler=true

# Enable/disable JPA auditing
restforge.enable-auditing=true

# Pagination settings
restforge.pagination.default-page-size=20
restforge.pagination.max-page-size=100

API Endpoints

RestForge automatically provides the following endpoints for each entity:

  • GET /api/{resource} - Get all resources
  • GET /api/{resource}/page - Get paginated resources
  • GET /api/{resource}/{id} - Get resource by ID
  • POST /api/{resource} - Create new resource
  • PUT /api/{resource}/{id} - Update resource
  • DELETE /api/{resource}/{id} - Delete resource
  • GET /api/{resource}/count - Count resources
  • GET /api/{resource}/exists/{id} - Check if resource exists

License

Copyright © 2025

About

Kit de infraestructura para forjar CRUD REST en Spring Boot: DTOs, mappers, errores y paginación

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages