Spaces:
Build error
Download backend/API_EXAMPLES.md from jinksQspider/fmpro: direct link, hf CLI and curl.
- Browser
- Download file 6.93 kB
-
https://huggingface.co/spaces/jinksQspider/fmpro/resolve/main/backend/API_EXAMPLES.md
- Command line
-
hf download hf://spaces/jinksQspider/fmpro/backend/API_EXAMPLES.md
-
curl -L -o API_EXAMPLES.md https://huggingface.co/spaces/jinksQspider/fmpro/resolve/main/backend/API_EXAMPLES.md
"""Comprehensive API Testing Examples"""
Authentication Examples
Register New User
POST http://localhost:8000/api/auth/register Content-Type: application/json
{ "email": "harsh@company.com", "password": "SecurePassword123", "full_name": "Harsh Kumar" }
Expected Response (201)
{ "user": { "id": "550e8400-e29b-41d4-a716-446655440000", "email": "harsh@company.com", "full_name": "Harsh Kumar", "role": "user", "tenant_id": "660e8400-e29b-41d4-a716-446655440000", "is_active": true, "created_at": "2024-01-15T10:30:00Z" }, "tokens": { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "bearer", "expires_in": 1800 }, "tenant": { "id": "660e8400-e29b-41d4-a716-446655440000", "name": "org-company.com", "plan": "free", "api_quota": 10000, "created_at": "2024-01-15T10:30:00Z" } }
Login
POST http://localhost:8000/api/auth/login Content-Type: application/json
{ "email": "harsh@company.com", "password": "SecurePassword123" }
Expected Response (200)
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "bearer", "expires_in": 1800 }
Refresh Token
POST http://localhost:8000/api/auth/refresh Content-Type: application/json
{ "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
Expected Response (200)
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "bearer", "expires_in": 1800 }
Get Current User
GET http://localhost:8000/api/auth/me Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
{ "id": "550e8400-e29b-41d4-a716-446655440000", "email": "harsh@company.com", "full_name": "Harsh Kumar", "role": "user", "tenant_id": "660e8400-e29b-41d4-a716-446655440000", "is_active": true, "created_at": "2024-01-15T10:30:00Z" }
Face Operations Examples
Register Face (Form Data with File)
POST http://localhost:8000/api/face/register Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... Content-Type: multipart/form-data
person_id: EMP001 name: Harsh Kumar image: @/path/to/harsh_photo.jpg metadata: {"department": "Engineering", "designation": "Senior Developer"}
Expected Response (201)
{ "id": "770e8400-e29b-41d4-a716-446655440000", "person_id": "EMP001", "name": "Harsh Kumar", "image_url": "s3://face-embeddings/...", "face_quality_score": 0.92, "created_at": "2024-01-15T10:35:00Z" }
Register Multiple Faces for Same Person
POST http://localhost:8000/api/face/register Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... Content-Type: multipart/form-data
person_id: EMP001 name: Harsh Kumar image: @/path/to/harsh_photo_2.jpg metadata: {}
Recognize Faces (Upload Frame)
POST http://localhost:8000/api/face/recognize Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... Content-Type: multipart/form-data
image: @/path/to/test_frame.jpg threshold: 0.5 return_bboxes: true
Expected Response (200)
{ "faces_detected": 2, "recognized": [ { "person_id": "EMP001", "name": "Harsh Kumar", "confidence": 0.96, "bbox": [100, 150, 250, 350], "embedding_id": "770e8400-e29b-41d4-a716-446655440000" }, { "person_id": "EMP002", "name": "John Doe", "confidence": 0.88, "bbox": [400, 200, 550, 450], "embedding_id": "880e8400-e29b-41d4-a716-446655440000" } ], "unrecognized_count": 0, "processing_time_ms": 245.67 }
List Registered Embeddings
GET http://localhost:8000/api/face/embeddings?skip=0&limit=100 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Optional filters:
GET http://localhost:8000/api/face/embeddings?person_id=EMP001&skip=0&limit=100
Expected Response (200)
[ { "id": "770e8400-e29b-41d4-a716-446655440000", "person_id": "EMP001", "name": "Harsh Kumar", "image_url": "s3://face-embeddings/...", "face_quality_score": 0.92, "embedding_dim": 512, "face_angle": "frontal", "created_at": "2024-01-15T10:35:00Z", "updated_at": "2024-01-15T10:35:00Z" } ]
Get Recognition Logs
GET http://localhost:8000/api/face/logs?skip=0&limit=100 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
[ { "id": "990e8400-e29b-41d4-a716-446655440000", "recognized_person_id": "EMP001", "confidence": 0.96, "source": "api", "timestamp": "2024-01-15T10:40:00Z" } ]
Delete Embedding
DELETE http://localhost:8000/api/face/embeddings/770e8400-e29b-41d4-a716-446655440000 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
{ "message": "Embedding deleted successfully" }
Admin Endpoints
Get Analytics
GET http://localhost:8000/api/admin/analytics Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
{ "total_tenants": 1, "total_users": 5, "total_face_embeddings": 42, "total_recognition_logs": 156, "total_api_calls": 1024, "recognitions_today": 25, "faces_registered_today": 3 }
List All Users
GET http://localhost:8000/api/admin/users?skip=0&limit=100 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
[ { "id": "550e8400-e29b-41d4-a716-446655440000", "email": "harsh@company.com", "full_name": "Harsh Kumar", "role": "user", "tenant_id": "660e8400-e29b-41d4-a716-446655440000", "is_active": true, "created_at": "2024-01-15T10:30:00Z", "face_embeddings_count": 3 } ]
Delete User (Admin Only)
DELETE http://localhost:8000/api/admin/users/550e8400-e29b-41d4-a716-446655440000 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Expected Response (200)
{ "message": "User deleted successfully" }
Health & Status
Health Check
GET http://localhost:8000/health
Expected Response (200)
{ "status": "healthy", "app": "Face Inference SaaS Platform", "version": "1.0.0" }
Root Info
Expected Response (200)
{ "app": "Face Inference SaaS Platform", "version": "1.0.0", "docs": "/docs", "openapi_schema": "/openapi.json" }
Error Responses
Invalid Credentials (401)
{ "detail": "Invalid email or password" }
Unauthorized (401)
{ "detail": "Not authenticated" }
Forbidden (403)
{ "detail": "Admin access required" }
Not Found (404)
{ "detail": "Embedding not found" }
Validation Error (422)
{ "detail": [ { "loc": ["body", "email"], "msg": "invalid email format", "type": "value_error.email" } ] }
No Faces Detected (400)
{ "detail": "No faces detected in image" }
Server Error (500)
{ "detail": "Face recognition failed" }