Skip to main content
POST
/
api
/
register
Register User
curl --request POST \
  --url https://api.example.com/api/register \
  --header 'Content-Type: application/json' \
  --data '
{
  "json": "<string>"
}
'
{
  "status": "<string>",
  "code": "<string>",
  "message": "<string>",
  "user": {
    "id": 123,
    "name": "<string>",
    "surname": "<string>",
    "email": "<string>",
    "password": "<string>",
    "role": "<string>",
    "created_at": "<string>",
    "updated_at": "<string>"
  }
}

Overview

Registers a new user in the system. The endpoint validates the input data, hashes the password using SHA-256, and creates a user with the default ROLE_USER role.

Request

Body Parameters

The request body must contain a json parameter with a JSON string containing the user details.
json
string
required
JSON string containing the user registration data with the following fields:
name
string
required
User’s first name. Must contain only alphabetic characters.
surname
string
required
User’s last name. Must contain only alphabetic characters.
email
string
required
User’s email address. Must be a valid email format and unique in the system.
password
string
required
User’s password. Will be hashed using SHA-256 before storage.

Request Example

cURL
curl -X POST https://your-domain.com/api/register \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d 'json={"name":"John","surname":"Doe","email":"[email protected]","password":"secretpassword123"}'

Response

Success Response (200)

status
string
Response status. Returns "success" when user is created successfully.
code
string
HTTP status code as string. Returns "200" for success.
message
string
Human-readable success message: "El usuario se ha creado correctamente"
user
object
The created user object containing:
id
integer
Unique user identifier
name
string
User’s first name
surname
string
User’s last name
email
string
User’s email address
password
string
Hashed password (SHA-256)
role
string
User role, defaults to "ROLE_USER"
created_at
string
Timestamp of account creation
updated_at
string
Timestamp of last update

Success Example

{
  "status": "success",
  "code": "200",
  "message": "El usuario se ha creado correctamente",
  "user": {
    "id": 1,
    "name": "John",
    "surname": "Doe",
    "email": "[email protected]",
    "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
    "role": "ROLE_USER",
    "created_at": "2026-03-04T10:30:00.000000Z",
    "updated_at": "2026-03-04T10:30:00.000000Z"
  }
}

Error Responses

Returned when the input data fails validation.
{
  "status": "error",
  "code": "404",
  "message": "El usuario no se ha creado",
  "errors": {
    "email": [
      "The email has already been taken."
    ],
    "name": [
      "The name field is required."
    ]
  }
}
Common validation errors:
  • name: Must be present and contain only alphabetic characters
  • surname: Must be present and contain only alphabetic characters
  • email: Must be a valid email format and not already registered
  • password: Must be present
Returned when the json parameter is missing or malformed.
{
  "status": "error",
  "code": "404",
  "message": "Los datos enviados no son correctos"
}

Important Notes

Password Security: Passwords are hashed using SHA-256 algorithm before being stored in the database. The same hashing method must be used during login authentication.
Default Role: All newly registered users are automatically assigned the ROLE_USER role. This role cannot be changed during registration.
Data Trimming: All input fields are automatically trimmed of leading and trailing whitespace before validation.
JSON Parameter Format: The request requires a json parameter containing a JSON string, not direct JSON in the request body. This is a specific requirement of this API implementation.

Build docs developers (and LLMs) love