Skip to main content
POST
/
usuarios
Create User
curl --request POST \
  --url https://api.example.com/usuarios \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "password": "<string>"
}
'
{
  "id": 123,
  "email": "<string>",
  "password": "<string>"
}
This endpoint creates a new user account in the PostgreSQL database using Prisma ORM. The user data is stored with the provided email and password.

Endpoint

POST /usuarios

Request Body

email
string
required
The user’s email address. Must be unique in the database.
password
string
required
The user’s password. This will be stored as provided (note: password hashing should be implemented for security).

Response

id
integer
The unique identifier assigned to the newly created user
email
string
The email address of the created user
password
string
The password as stored in the database

Status Codes

  • 201 Created - User successfully created
  • 500 Internal Server Error - Database error or validation failure

Example Request

curl -X POST http://localhost:3000/usuarios \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "securePassword123"
  }'

Example Response

Success (201)

{
  "id": 1,
  "email": "user@example.com",
  "password": "securePassword123"
}

Error (500)

{
  "error": "Error al insertar en Postgres"
}

Error Handling

Common errors include:
  • Duplicate email: If the email already exists in the database
  • Missing required fields: If email or password is not provided
  • Database connection issues: If the PostgreSQL database is unavailable

Implementation Details

The endpoint implementation (from /backend/index.js:24-36):
app.post('/usuarios', async (req, res) => {
  try {
    const nuevoUsuario = await prisma.user.create({
      data: {
        email: req.body.email,
        password: req.body.password
      }
    });
    res.status(201).json(nuevoUsuario);
  } catch (error) {
    console.log("DETALLE DEL ERROR:", error);
    res.status(500).json({ error: "Error al insertar en Postgres" });
  }
});

Security Considerations

The current implementation stores passwords in plain text. For production use, implement password hashing using bcryptjs (already imported in the project).

Build docs developers (and LLMs) love