This project is an example of implementing a Rest API using Spring Boot following instructions from the alura course.
Requirements
How to use?
Endpoints
Adding H2 Database dependency and Console Browser
Commits Log
Swagger
- Maven ⚙️
- Java 8+ ☕
Run the command to compile:
mvn clean install
To start the project. Run:
mvn spring-boot:run
Image containing command result mvn spring-boot:run |
After running the above command, the application will be available at: http://localhost:8080
Link: 🔗 http://localhost:8080/topicos?page=0&size=2&sort=id,asc
Method GET
Link: 🔗 http://localhost:8080/topicos/{ID}
Method POST
If you want to add a new record to try the endpoint, you can run the following CURL command in the terminal. And that will create a new record.
curl -X POST \
http://localhost:8080/topicos \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"titulo": "Question About Spring Validation",
"mensagem": "Currently, should I add a new dependency for this to work?",
"nomeCurso": "Spring Boot"
}'
Or it's also possible through postman:
Screenshot with the request made through postman. |
Connection Settings: 🎲
Driver Class: org.h2.Driver JDBC URL: jdbc:h2:mem:alura-forum User Name: sa Password: (leave this field empty)
H2 database interface showing tables in a column on the left of the screen. |
The data located in the following path will be loaded at startup.
Initial data structure: src/main/resources/data.sql 📄
To search topics using the filter, you must enter the parameter in the URL: http://localhost:8080/topicos?param=Spring+Boot
The URL to access the Swagger is: http://localhost:8080/swagger-ui/index.html
First, you must authenticate with a user, through endpoint /auth
using for example:
{
"email": "[email protected]",
"senha": "123456"
}
There are two credentials available:
login: aluno@email.com
password: 123456
login: moderador@email.com
password: 123456
Swagger's screenshot. |