Create a new user account in the system.

Endpoint

POST /users/create

Request

Headers

NameRequiredDescription
Content-TypeYesapplication/json

Body

{
  "email": "user@example.com",
  "password": "userpassword",
  "fname": "John",
  "phone": "1234567890"
}
FieldTypeRequiredDescription
emailstringYesUser’s email address
passwordstringYesUser’s password
fnamestringYesUser’s first name
phonestringYesUser’s phone number

Response

Success Response

Code: 201 Created

Content example: this example will not work please use your won data

{
  "id": "abc123",
  "email": "user@example.com",
  "fname": "John",
  "phone": "1234567890",
  "createdAt": "2024-10-11T12:34:56.789Z"
}
FieldTypeDescription
idstringUnique identifier for the user
emailstringUser’s email address
fnamestringUser’s first name
phonestringUser’s phone string
createdAtstringTimestamp of account creation

Error Response

Code: 500 Internal Server Error

Content example:

{
  "statusCode": 500,
  "message": "Internal Server Error",
  "error": "Internal Server Error"
}

Notes

  • This endpoint creates a new user with the provided email, password, first name, and phone number.
  • The user’s password will be securely hashed before storage.

Example Usage

JavaScript (Fetch API)

async function createUser(email, password, fname, phone) {
  try {
    const response = await fetch("http://your-api-url/users/create", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ email, password, fname, phone }),
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    console.log("User created successfully:", data);
    return data;
  } catch (error) {
    console.error("Error creating user:", error);
  }
}

// Usage
createUser("user@example.com", "userpassword", "John", 1234567890);

Security Considerations

  • Ensure HTTPS is used to protect sensitive information.
  • Implement input validation to prevent malicious data entry.
  • Store passwords securely using strong hashing algorithms (e.g., bcrypt).
  • Consider implementing rate limiting to prevent abuse of the create user endpoint.