Quickstart

The quickstart documentation will demonstrate how to install and use Sakura Boot with the hypermedia module to create a simple API application with logging facilities.

Prerequisites

See Requirements for prerequisites.

Base application

If a base application is needed before this quickstart, see the basic quickstart section.

Project structure

The project structure is the same as the basic module quickstart.

To initialize a Spring Boot application, go to https://start.spring.io/. From there, it will be easier to create a new project.

Installation

The log module is already included in the basic module by default. So the installation will be the same as the basic module quickstart.

Configuration

The configuration of the project is the same as the basic quickstart section.

For a production-ready application, remove the spring.jpa.hibernate.ddl-auto property.

Create the application

The next part is to write the application code.
The application will use UUID as the primary key of the entity. It is possible to use any other primary key (e.g., Long, String, etc).

Again, if a base application is needed before this quickstart, see the basic quickstart section.

Service

The service in SimpleService.java can change based on the modules that are used.

Here is an example of the service that uses the log module.

SimpleService.java
package com.example.demo.business;

import java.util.UUID;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

import org.sansenshimizu.sakuraboot.basic.api.business.BasicService;
import org.sansenshimizu.sakuraboot.log.api.Loggable;

import com.example.demo.persistence.SimpleEntity;
import com.example.demo.persistence.SimpleRepository;
import com.example.demo.presentation.SimpleFilter;

@Service
public class SimpleService implements BasicService<SimpleEntity, UUID>, Loggable {

    private final SimpleRepository repository;

    private final ObjectMapper objectMapper;

    @Override
    public Class<Simple> getEntityClass() {

        return Simple.class;
    }

    // Required arg constructor, getters, etc. if lombok is not used.
}

For lombok users, add the annotation on top of the class:

@Getter
@RequiredArgsConstructor
@Service

Controller

The controller in SimpleController.java can change based on the modules that are used.

Here is an example of the controller that uses the log module.

SimpleController.java
package com.example.demo.presentation;

import java.util.UUID;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.sansenshimizu.sakuraboot.basic.api.presentation.BasicController;
import org.sansenshimizu.sakuraboot.log.api.Loggable;

import com.example.demo.business.SimpleService;
import com.example.demo.persistence.SimpleEntity;

@RestController
@RequestMapping("/simples")
public class SimpleController
    implements BasicController<SimpleEntity, UUID, SimpleEntity>, Loggable {

    private final SimpleService service;

    // Required arg constructor, getters, etc. if lombok is not used.
}

For lombok users, add the annotation on top of the class:

@Getter
@RequiredArgsConstructor
@RestController
@RequestMapping("/simples")

The simple application with the log module is now ready to be used.

Usage

The usage is the same as the basic quickstart section.

Next steps

For more information on how to build and run a Spring Boot application, see here.

For more information about the spring-boot-docker-compose for local development with docker support, see here.

The quickstart application creates only one entity. The next step could be to add more entities with the necessary fields. For each new entity follow the same steps.

When building an application with different entities, it is possible to create relations between them.
For more information, see the Relationship section.

To customize the configuration for the application requirements, see the Configuration section.

If the quickstart section is not sufficient, other examples are available at the Examples section.