๐ API Documentation
27 views
API Documentation Overview
API Documentation Overview
Base URL: https://yourdomain.com/api/v1
Authentication: Laravel Sanctum (Bearer token)
Endpoints
Auth
POST /auth/loginโ get token (body:email,password,device_name)POST /auth/registerโ register patientGET /auth/meโ get current user (auth required)POST /auth/logoutโ revoke token (auth required)
Treatments (Public Read)
GET /treatmentsโ list (param:category)GET /treatments/{id}โ detail
Patients (Auth Required)
GET /patientsโ list (admin: all in clinic, patient: own only)POST /patientsโ create (staff only)GET /patients/{id}โ detailPUT /patients/{id}โ updateDELETE /patients/{id}โ delete (staff only)
Appointments (Auth Required)
GET /appointmentsโ list (param:date,status)POST /appointmentsโ createGET /appointments/{id}โ detailPUT /appointments/{id}โ updatePOST /appointments/{id}/cancelโ cancel (body:reason)DELETE /appointments/{id}โ delete
Example Login Flow
# Login
curl -X POST https://yourdomain.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "admin@klinik.com",
"password": "password",
"device_name": "mobile-app"
}'
# Response:
# {
# "token": "1|XXXXXXXXXXX",
# "user": {"id":1,"name":"Admin","email":"...","role":"owner"}
# }
# Use token
curl https://yourdomain.com/api/v1/patients \
-H "Authorization: Bearer 1|XXXXXXXXXXX" \
-H "Accept: application/json"
Rate Limiting
- Default: 60 requests/minute per token
- Login endpoint: 5 attempts/minute per IP
Error Format
{
"message": "The given data was invalid.",
"errors": {
"field_name": ["validation message"]
}
}
RBAC di API
- Patient role โ hanya bisa GET data sendiri (auto-filter by
user_id) - Staff role โ CRUD sesuai permission Spatie
- Unauthenticated โ 401, kecuali endpoint public (
/treatments)