API and features
HTTP contract, examples and rules actually enforced by the server.
Endpoint map
The examples use the deployment at compose.yml: http://localhost:8088/api. If you run Spring with Maven and a database accessible from the host, replace that base URL with http://localhost:7070/api. Send JSON using Content-Type: application/json. Protected routes require Authorization: Bearer TOKEN.
| Method | Route | Access | Success | Purpose |
|---|---|---|---|---|
| POST | /api/auth/register | Public | 201 | Create USER + issue JWT |
| POST | /api/auth/login | Public | 200 | Verify credentials + issue JWT |
| GET | /api/me | USER or ADMIN | 200 | JWT subject profile |
| GET | /api/users | ADMIN | 200 | Complete list ordered by id |
| POST | /api/users | ADMIN | 201 | Create an account and return its profile |
| PUT | /api/users/{id} | ADMIN | 200 | Update the complete account |
| DELETE | /api/users/{id} | ADMIN | 204 | Delete without a response body |
Public registration
curl -i http://localhost:8088/api/auth/register -H 'Content-Type: application/json' -d '{"name":"Ana Pérez","email":"ana@example.com","password":"Aprender123!"}'RegisterRequest accepts name (2–80 characters, nonblank), email (valid format, maximum 160) and password (8–72 characters, maximum 72 UTF-8 bytes). The server trims the name, lowercases the email, rejects duplicates, calculates a BCrypt hash and saves an active USER account. Sending role: "ADMIN" grants no permissions: the DTO has no such field and the controller assigns USER.
Login and authentication response
curl -i http://localhost:8088/api/auth/login -H 'Content-Type: application/json' -d '{"email":"ana@example.com","password":"Aprender123!"}'{
"accessToken": "JWT_DEVUELTO_POR_EL_SERVIDOR",
"tokenType": "Bearer",
"expiresIn": 900,
"user": {
"id": 3,
"name": "Ana Pérez",
"email": "ana@example.com",
"role": "USER",
"enabled": true
}
}Login returns 200; registration returns 201 in the same format. The id and token above are illustrative. Login validates nonblank email and password, up to 160 and 72 characters respectively, and the BCrypt limit of 72 bytes. It does not reapply the eight-character minimum: it verifies the stored credential. A missing email, incorrect password or disabled account produces 401 with a common message.
Query profiles and users
# Copia un token propio de la respuesta de login.
TOKEN='PEGA_AQUI_UN_TOKEN_USER_O_ADMIN'
curl -i http://localhost:8088/api/me -H "Authorization: Bearer $TOKEN"
# Usa un token ADMIN para esta operación.
ADMIN_TOKEN='PEGA_AQUI_UN_TOKEN_ADMIN'
curl -i http://localhost:8088/api/users -H "Authorization: Bearer $ADMIN_TOKEN"/me returns a UserResponse like the user object above. Its id comes from the validated JWT subject. /users returns an array of these objects, even when empty. There is no GET /api/users/{id} or search endpoint. Password hashes never appear in responses.
Create an account as ADMIN
curl -i http://localhost:8088/api/users -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' -d '{"name":"Luis Gómez","email":"luis@example.com","password":"Aprender123!","role":"USER","enabled":true}'Creation requires a non-null, nonblank password. ADMIN can create USER or ADMIN accounts and choose enabled. This endpoint returns only UserResponse; it neither signs in as the new account nor returns its token.
Edit and delete
# Sustituye 4 por el id real de otra cuenta de pruebas.
curl -i -X PUT http://localhost:8088/api/users/4 -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' -d '{"name":"Luis editado","email":"luis@example.com","password":"","role":"ADMIN","enabled":true}'
# Elimina esa cuenta de pruebas de forma permanente.
curl -i -X DELETE http://localhost:8088/api/users/4 -H "Authorization: Bearer $ADMIN_TOKEN"PUT requires name, email, role and enabled; it is not a partial PATCH update. An empty, null or omitted password preserves the hash; a new password must satisfy 8–72 characters and at most 72 bytes. Role accepts only USER or ADMIN; enabled must be a non-null boolean.
You cannot remove your own ADMIN role, disable or delete your own account. These operations return 409. You can modify other accounts, including other ADMIN accounts: there is no general last-administrator protection rule. Deletion removes the account row; disabling preserves it and prevents authentication.
Error responses
{
"status": 400,
"message": "Revisa los campos del formulario.",
"errors": {"email": "must be a well-formed email address"}
}Validation messages may vary with the validator's language. The common format is status, message and errors (a field map, usually empty for general errors). The additional BCrypt constraint may appear under the name passwordWithinBcryptLimit.
| Code | Meaning | Example |
|---|---|---|
| 400 | Invalid input | Malformed JSON, unknown role, short or excessive password. |
| 401 | Invalid identity | Missing token, altered signature, expiration, wrong issuer, deleted or disabled user. |
| 403 | Insufficient permission | USER attempts to manage users. A rejected CORS origin may also produce 403 with a different body. |
| 404 | Account not found | ADMIN edits or deletes a nonexistent id. |
| 409 | Conflict | Duplicate email or protection of the acting account. |
Guided practice
- Call /me without a token: 401.
- Register USER and use it on /me: 200; on /users: 403.
- Modify the JWT signature: 401.
- Repeat the registration email: 409.
- As ADMIN, create and disable an account. Its token stops granting access on the next request.
- Change a role and reuse the original token: the current database role applies.
You can also open docs/peticiones.http in a client supporting .http files. This project has no configured Swagger/OpenAPI.