curl --request POST \
--url https://api.example.com/registrar \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"nombre": "<string>",
"apellidos": "<string>"
}
'{
"mensaje": "<string>",
"exito": true
}Register a new user in the system
curl --request POST \
--url https://api.example.com/registrar \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>",
"nombre": "<string>",
"apellidos": "<string>"
}
'{
"mensaje": "<string>",
"exito": true
}POST /registrar
UsuarioRegistro Pydantic model:
null)null){
"mensaje": "Usuario creado",
"exito": true
}
{
"mensaje": "El usuario ya existe",
"exito": false
}
{
"mensaje": "Error: [error details]",
"exito": false
}
psycopg2.IntegrityError and returning exito: false instead of raising an HTTP exception. All database errors result in a rollback.
curl -X POST http://localhost:8000/registrar \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securepass123",
"nombre": "Juan",
"apellidos": "García"
}'
import requests
url = "http://localhost:8000/registrar"
data = {
"email": "[email protected]",
"password": "securepass123",
"nombre": "Juan",
"apellidos": "García"
}
response = requests.post(url, json=data)
result = response.json()
if result["exito"]:
print(f"Registration successful: {result['mensaje']}")
else:
print(f"Registration failed: {result['mensaje']}")
const axios = require('axios');
const registerUser = async () => {
try {
const response = await axios.post('http://localhost:8000/registrar', {
email: '[email protected]',
password: 'securepass123',
nombre: 'Juan',
apellidos: 'García'
});
if (response.data.exito) {
console.log(`Registration successful: ${response.data.mensaje}`);
} else {
console.log(`Registration failed: ${response.data.mensaje}`);
}
} catch (error) {
console.error('Request failed:', error.message);
}
};
registerUser();
nombre and apellidos fields default to null if not provided