A simple API in Spring Boot. It has some basic functions, like:
- User registration and authentication using JWT
- Perform CRUD operations of Tasks
- Some basics business rules enforced
My main goal is to showcase some concepts, such as:
- Migrations and model relationship
- Authentication configuration
- Routes definitions
- SOLID and KISS principles on a MVC architecture
The main tech behind it is Spring Boot and also some others Java libraries. For storaging, i'm using MySQL relational database
To run this application you must have installed on your environment:
Java
- For the main applicationMaven
- For library and packages managementMySQL
- For storaging and accessing data
Once you set up all necessary software and tools, run
cp src/main/resources/application.properties.local src/main/resources/application.properties
and fill out the bracketed values on that new copy's spring.datasource enviroment variables. Don't forget to set up a crypt hash for the jwt.secret
.
Then run
mvn spring-boot:run
to install all packages and run the application. If no errors is shown and the CLI shows the server is running, you're good to go!
curl --location 'http://localhost:8080/api/users/register' \
--header 'Content-Type: application/json' \
--data '{
"name": "T. Soprano",
"username": "t.soprano",
"password": "password"
}'
curl --location 'http://localhost:8080/api/users/login' \
--header 'Content-Type: application/json' \
--data '{
"username": "t.soprano",
"password": "password"
}'
curl --location 'http://localhost:8080/api/task/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
"title": "New Task again",
"description": "Here is a description",
"type": "feature"
}'
Replace {created_by}
with a User Id
Replace {status}
with any of the following: new, in_dev, in_qa, blocked, closed
Replace {type}
with any of the following: feature, bugfix, hotfix
curl --location 'http://localhost:8080/api/task/list?type={type}&status={status}&created_by={created_by}' \
--header 'Authorization: Bearer {token}'
curl --location 'http://localhost:8080/api/task/view/{taskId}' \
--header 'Authorization: Bearer {token}'
curl --location --request PUT 'http://localhost:8080/api/task/update/{taskId}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {token}' \
--data '{
"type": "hotfix"
}'
curl --location --request DELETE 'http://localhost:8080/api/task/delete/{taskId}' \
--header 'Authorization: Bearer {token}'
curl --location --request PUT 'http://localhost:8080/api/task/close/{taskId}' \
--header 'Authorization: Bearer {token}'