Skip to content

Spring-Boot-Framework/springboot-api-rest-example

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡§πŸ‡· In Portuguese

🐬 MySQL/MariaDB (outdated) implementation

Tecnologias

Spring Boot API RESTful

A complete user registry, with access permissions, JWT token, integration and unit tests, using the RESTful API pattern.



Live demo on heroku

Demonstration

Table of Contents

Features

Tecnologias

Requirements

  • Postgres: ^13
  • Java: ^17
  • Maven: ^3.8.4

This project was started with Spring Initializr.

Entities

database diagram

🚨 draw.io file here

Installation

# clone the repository and access the directory.
$ git clone [email protected]:Throyer/springboot-api-crud.git && cd springboot-api-crud

# download dependencies
$ mvn install -DskipTests

# run the application
$ mvn spring-boot:run

# run the tests
$ mvn test

# to build for production
$ mvn clean package

# to generate the coverage report after testing (available at: target/site/jacoco/index.html)
$ mvn jacoco:report

Tests

Coverage Status

Running a specific test

use the parameter -Dtest=<class>#<method>

for example the integration test. creating a user:

$ mvn test -Dtest=UsersControllerIntegrationTests#should_save_a_new_user

Swagger

Once the application is up, it is available at: localhost:8080/documentation

example on heroku


Database Migrations

Creating database migration files

  • Java based migrations

    mvn migration:generate -Dname=my-migration-name
  • SQL based migrations

    mvn migration:generate -Dname=my-migration-name -Dsql

Docker examples

docker compose for development

cd docker
docker-compose -p common-api-development -f docker-compose.dev.yml up -d

Building image for production

cd docker
DOCKER_BUILDKIT=1 docker build -f Dockerfile.prod -t common-api:4.1.2 ../

docker compose for production

cd docker
cp .env.example .env

docker-compose -p common-api -f docker-compose.prod.yml up -d

Environment variables

Description Parameter Default values
server port SERVER_PORT 8080
database url DB_URL localhost:5432/common_app
username (database) DB_USERNAME root
user password (database) DB_PASSWORD root
displays the generated sql in the logger DB_SHOW_SQL false
set maximum database connections DB_MAX_CONNECTIONS 5
secret value in token generation TOKEN_SECRET secret
token expiration time in hours TOKEN_EXPIRATION_IN_HOURS 24
refresh token expiry time in days REFRESH_TOKEN_EXPIRATION_IN_DAYS 7
SMTP server address SMTP_HOST smtp.gmail.com
SMTP server port SMTP_PORT 587
SMTP username SMTP_USERNAME user
SMTP server password SMTP_PASSWORD secret
time for recovery email to expire MINUTES_TO_EXPIRE_RECOVERY_CODE 20
max requests per minute MAX_REQUESTS_PER_MINUTE 10
swagger username SWAGGER_USERNAME null
swagger password SWAGGER_PASSWORD null

these variables are defined in: application.properties

# to change the value of some environment variable at runtime
# on execution, just pass it as a parameter. (like --SERVER_PORT=80).
$ java -jar api-4.1.2.jar --SERVER_PORT=80

All options of aplication.properties here.

All features of Spring Boot.

About

Spring Boot API RESTful with tests, swagger e JWT πŸš€

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 76.0%
  • HTML 21.1%
  • CSS 2.1%
  • Other 0.8%