Skip to main content
POST
/
api
/
users
Create User
curl --request POST \
  --url https://api.example.com/api/users \
  --header 'Content-Type: application/json' \
  --data '
{
  "username": "<string>",
  "email": "<string>",
  "password_hash": "<string>",
  "firstname": "<string>",
  "lastname": "<string>",
  "phone_number": "<string>",
  "role": "<string>",
  "is_active": true,
  "profileImage": "<string>"
}
'
{
  "id": 123,
  "username": "<string>",
  "email": "<string>",
  "password_hash": "<string>",
  "firstname": "<string>",
  "lastname": "<string>",
  "phone_number": "<string>",
  "role": "<string>",
  "is_active": true,
  "profileImage": "<string>",
  "created_at": {},
  "updated_at": {}
}

Overview

This endpoint creates a new user in the DriveX system. The password is automatically hashed using BCrypt encryption before storage.

Request

username
string
required
Unique username for the user
email
string
required
User’s email address
password_hash
string
required
User’s password in plain text (will be encrypted automatically)
firstname
string
User’s first name
lastname
string
User’s last name
phone_number
string
User’s phone number
role
string
User’s role in the system (e.g., ADMIN, USER, DRIVER)
is_active
boolean
Whether the user account should be active. Defaults to true
profileImage
string
URL or path to the user’s profile image
curl -X POST 'http://localhost:8080/api/users' \
  -H 'Content-Type: application/json' \
  -d '{
    "username": "johndoe",
    "email": "[email protected]",
    "password_hash": "mySecurePassword123",
    "firstname": "John",
    "lastname": "Doe",
    "phone_number": "+1234567890",
    "role": "USER",
    "is_active": true,
    "profileImage": "/images/profiles/johndoe.jpg"
  }'

Response

id
long
Unique identifier assigned to the newly created user
username
string
User’s username
email
string
User’s email address
password_hash
string
Encrypted password hash
firstname
string
User’s first name
lastname
string
User’s last name
phone_number
string
User’s phone number
role
string
User’s role in the system
is_active
boolean
Whether the user account is active
profileImage
string
URL or path to the user’s profile image
created_at
timestamp
Timestamp when the user was created
updated_at
timestamp
Timestamp when the user was last updated

Example Response

{
  "id": 3,
  "username": "johndoe",
  "email": "[email protected]",
  "password_hash": "$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy",
  "firstname": "John",
  "lastname": "Doe",
  "phone_number": "+1234567890",
  "role": "USER",
  "is_active": true,
  "profileImage": "/images/profiles/johndoe.jpg",
  "created_at": "2024-01-25T15:30:00Z",
  "updated_at": "2024-01-25T15:30:00Z"
}

Notes

  • The id field in the request body is automatically set to null to ensure a new user is created
  • Passwords are automatically hashed using BCrypt encryption before being stored
  • Send the password in plain text in the password_hash field - the server handles encryption

Build docs developers (and LLMs) love