Usuário padrão:
- Username: [email protected]
- Senha: developer
- Authorities: manager
Verifique se a aplicação está funcionando corretamente.
curl -X GET \
'http://localhost:8080/api/actuator/health' \
--header 'Accept: application/hal+json'
Resposta esperada:
{
"status": "UP"
}
Porta de entrada da aplicação.
curl -X GET \
'http://localhost:8080/api/' \
--header 'Accept: application/hal+json'
Resposta esperada:
{
"_links": {
"createUser": {
"href": "http://localhost:8080/api/users/save"
}
}
}
Cria um usuário sem uma função definida.
curl -X POST \
'http://localhost:8080/api/users/save' \
--header 'Accept: application/hal+json' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
"password": "test"
}'
Resposta esperada:
{
"email": "[email protected]",
"authorities": [],
"_links": {
"self": {
"href": "http://localhost:8080/api/roles/get/all"
}
}
}
Cria uma função/cargo.
Somente para usuários com a role manager.
Pode ser em caixa alta ou caixa baixa: TEST ou test.
curl -X POST \
'http://localhost:8080/api/roles/save' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"roleName": "test"
}'
Resposta esperada:
{
"name": "test",
"_links": {
"self": [
{
"href": "http://localhost:8080/api/roles/add"
},
{
"href": "http://localhost:8080/api/roles/get/all"
}
]
}
}
Adiciona uma função/cargo ao usuário.
Inicialmente existem duas opções de roles/scopes pré-definidas: read ou write.
Se você tentar adicionar a role manager ou admin, você recebera Method Not Allowed (405).
curl -X PUT \
'http://localhost:8080/api/roles/add' \
--header 'Accept: application/hal+json' \
--header 'Content-Type: application/json' \
--data-raw '{
"roleName": "read",
"userEmail": "[email protected]"
}'
Resposta esperada:
{
"_links": {
"generateTokens": {
"href": "http://localhost:8080/api/token"
}
}
}
Cria um jwt token com as credenciais do usuário.
curl -X POST \
'http://localhost:8080/api/token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
"password":"test"
}'
Resposta esperada:
{
"type": "bearer",
"access_token": {
"exp": "2023-01-06T22:09:35.728410385Z",
"token": "<token>"
},
"refresh_token": {
"exp": "2023-01-07T21:44:35.728410385Z",
"token": "<token>"
}
}
Criar novos tokens a partir de um refresh token.
curl -X GET \
'http://localhost:8080/api/refresh' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"token": "<token>"
}'
Resposta esperada:
{
"type": "bearer",
"access_token": {
"exp": "2023-01-06T22:09:35.728410385Z",
"token": "<token>"
},
"refresh_token": {
"exp": "2023-01-07T21:44:35.728410385Z",
"token": "<token>"
}
}
Salva uma entidade Pessoa.
curl -X POST \
'http://localhost:8080/api/persons/save' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"firstName": "Nome",
"lastName": "Sobrenome",
"dateOfBirth": "dd-MM-yyyy"
}'
Resposta esperada:
{
"personId": 1,
"firstName": "Nome",
"lastName": "Sobrenome",
"dateOfBirth": "dd-MM-yyyy",
"_links": {
"createAddress": {
"href": "http://localhost:8080/api/addresses/save?personId=1"
},
"self": [
{
"href": "http://localhost:8080/api/persons/get?personId=1"
},
{
"href": "http://localhost:8080/api/persons/get/all"
}
]
}
}
Procura por uma pessoa baseada no identificador.
curl -X GET \
'http://localhost:8080/api/persons/get?personId=1' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
{
"personId": 1,
"firstName": "Nome",
"lastName": "Sobrenome",
"dateOfBirth": "dd-MM-yyyy",
"_links": {
"self": [
{
"href": "http://localhost:8080/api/persons/update?personId=1"
},
{
"href": "http://localhost:8080/api/persons/delete?personId=1"
}
],
"getAddressesByPerson": {
"href": "http://localhost:8080/api/addresses/get/all?personId=1"
}
}
}
Procura por todas as pessoas disponíveis.
curl -X GET \
'http://localhost:8080/api/persons/get/all?page=0&size=1' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
{
"_embedded": {
"personList": [
{
"personId": 1,
"firstName": "Nome",
"lastName": "Sobrenome",
"dateOfBirth": "dd-MM-yyyy"
}
]
}
}
Atualiza uma pessoa.
curl -X PUT \
'http://localhost:8080/api/persons/update?personId=1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"firstName": "Nome",
"lastName": "Sobrenome",
"dateOfBirth": "dd-MM-yyyy"
}'
Resposta esperada:
No content 204
Remove uma pessoa.
curl -X DELETE \
'http://localhost:8080/api/persons/delete?personId=1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
No content 204
Cria um endereço para uma pessoa específica.
curl -X POST \
'http://localhost:8080/api/addresses/save?personId=2' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
"city": "Cidade",
"number": "10A",
"street": "Rua",
"postalCode": "00000000"
}'
Resposta esperada:
{
"addressId": 1,
"street": "Rua",
"postalCode": "00000000",
"number": "10A",
"city": "Cidade",
"preferred": false,
"_links": {
"self": [
{
"href": "http://localhost:8080/api/addresses/edit/preferred?personId=2&addressId=4"
},
{
"href": "http://localhost:8080/api/addresses/get/all?personId=2"
}
]
}
}
Busca por todos os endereços de uma pessoa.
curl -X GET \
'http://localhost:8080/api/addresses/get/all?personId=1&page=0&size=1' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
{
"_embedded": {
"addressList": [
{
"addressId": 1,
"street": "Rua",
"postalCode": "00000000",
"number": "10A",
"city": "Cidade",
"preferred": false
},
{
"addressId": 2,
"street": "Rua",
"postalCode": "00000000",
"number": "10B",
"city": "Cidade",
"preferred": true
}
]
}
}
Define o endereço preferencial/principal da pessoa.
curl -X PUT \
'http://localhost:8080/api/addresses/edit/preferred?personId=2&addressId=1' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
No content 204
Busca o endereço preferencial/principal da pessoa.
curl -X GET \
'http://localhost:8080/api/addresses/get/preferred?personId=2&addressId=1' \
--header 'Accept: application/hal+json' \
--header 'Authorization: Bearer <token>'
Resposta esperada:
{
"addressId": 2,
"street": "Rua",
"postalCode": "",
"number": "10B",
"city": "Cidade",
"preferred": true,
"_links": {
"self": [
{
"href": "http://localhost:8080/api/addresses/edit/preferred?personId=2&addressId={addressId}",
"templated": true
},
{
"href": "http://localhost:8080/api/addresses/get/all?personId=2"
}
]
}
}