This project was made to test Spring Boot with an example API of Users.
- Generate a new project with Spring Initializr and select next options:
- Language: ⬤ Java
- Project: ⬤ Maven
- Spring Boot Version: ⬤ 3.1.5
- Packaging: ⬤ Jar
- Java Version: ⬤ 11
- Add next dependencies:
- Spring Web
WEB
- Spring Data JDBC
SQL
- Spring Web
- Run an instance of PostgreSQL with docker using next commmand:
docker run -d --name postgresql -e POSTGRES_USER=pgsql -e POSTGRES_PASSWORD=s3cr3t -e POSTGRES_DB=example -p 5432:5432 postgres:14
- Execute 01_CREATE-TABLE.sql in your database instance.
- Configure DataSource in your Java project (in application.properties file)
To test this project, first run the Java application:
mvn spring-boot:run
And then execute next CURL command:
curl -X POST localhost:8080/api/user -H 'Content-Type: application/json' -d '{ "name": "John Doe"}'
You will be able to see a JSON response:
{
"id": 1,
"name": "John Doe"
}