# Documentazione API
Cognitor Assistant espone un'API REST basata su FastAPI per l'integrazione con altri sistemi.
Endpoint
GET /health
Health check dell'applicazione.
Response:
json
{
"status": "ok"
}POST /auth/token
Autenticazione utente, restituisce JWT token.
Request Body (form-urlencoded):
username: Username dell'utentepassword: Password dell'utente
Response:
json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer"
}Esempio:
bash
curl -X POST http://localhost:8000/auth/token \
-d "username=admin&password=admin123"POST /chatbot/message
Invia un messaggio al chatbot (richiede autenticazione).
Headers:
Authorization: Bearer token JWT
Request Body:
json
{
"message": "Ciao!",
"session_id": "optional-session-id"
}Response:
json
{
"response": "Ciao! Come posso aiutarti?",
"session_id": "uuid-della-sessione"
}Esempio:
bash
curl -X POST http://localhost:8000/chatbot/message \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"message": "Ciao!"}' Autenticazione
L'API utilizza JWT (JSON Web Tokens) per l'autenticazione. Per accedere agli endpoint protetti:
- Ottenere un token tramite
/auth/token - Includere il token nell'header
Authorization: Bearer
Errori
Gli endpoint possono restituire i seguenti codici di errore:
401 Unauthorized: Token mancante o invalido404 Not Found: Risorsa non trovata500 Internal Server Error: Errore interno del server
CORS
L'API configura CORS per permettere richieste da qualsiasi origine (allow_origins=["*"]).