| title | Capstone API |
|---|---|
| emoji | π |
| colorFrom | blue |
| colorTo | purple |
| sdk | docker |
| pinned | false |
REST API dengan Django, JWT Authentication, dan dokumentasi Swagger/ReDoc.
Setelah deploy, akses API documentation di:
- Swagger UI:
https://[your-username]-[space-name].hf.space/api/docs/ - ReDoc:
https://[your-username]-[space-name].hf.space/api/redoc/
Pastikan file-file ini sudah ada di repository:
django-capstone-project/
βββ Dockerfile # Sudah dikonfigurasi untuk Hugging Face
βββ README.md # File ini
βββ requirements.txt # Dependencies
βββ capstone/ # Project settings
βββ users/ # User app
βββ core/ # Core utilities
Di Settings β Repository secrets atau Space secrets, tambahkan:
| Variable | Value | Keterangan |
|---|---|---|
SECRET_KEY |
your-django-secret-key |
Django secret key |
DEBUG |
False |
Production mode |
JWT_SECRET_KEY |
your-jwt-secret-key |
JWT signing key |
DB_NAME |
postgres |
Database name |
DB_USER |
postgres.wtuvrsjxcgfihoyhowal |
Supabase user |
DB_PASSWORD |
your-password |
Supabase password |
DB_HOST |
aws-1-ap-southeast-1.pooler.supabase.com |
Supabase host |
DB_PORT |
6543 |
Supabase port |
DB_SSLMODE |
require |
SSL mode |
ACCESS_TOKEN_EXPIRY |
60 |
Access token expiry (detik) |
REFRESH_TOKEN_EXPIRY |
604800 |
Refresh token expiry (detik) |
-
Buat Space baru di Hugging Face:
- Pilih Docker sebagai SDK
- Repository name:
capstone-api(atau yang Anda inginkan)
-
Upload/Push code ke repository Hugging Face:
git clone https://huggingface.co/spaces/[username]/[space-name] cd [space-name] # Copy semua file project ke sini git add . git commit -m "Initial deployment" git push
-
Atau gunakan GitHub integration:
- Hubungkan GitHub repository ke Hugging Face Space
- Enable auto-deploy on push
Setelah deploy berhasil:
- Buka Space URL:
https://[username]-[space-name].hf.space/ - Cek API docs:
/api/docs/ - Test endpoint dengan Swagger UI
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/auth/register |
- | Register user baru |
POST |
/api/auth/login |
- | Login & dapatkan tokens |
POST |
/api/auth/refresh-token |
- | Refresh access token |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/api/me |
Bearer | Get current user data |
| URL | Description |
|---|---|
/api/docs/ |
Swagger UI - Interactive API docs |
/api/redoc/ |
ReDoc - Alternative API docs |
/api/schema/ |
OpenAPI Schema (JSON) |
{
"success": true,
"statusCode": 200,
"message": "Pesan deskriptif",
"data": {},
"metadata": {
"limit": 10,
"page": 1,
"totalItems": 2,
"totalPages": 1
}
}curl -X POST https://[username]-[space-name].hf.space/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"name": "Test User",
"nickname": "Tester",
"username": "testuser",
"password": "password123"
}'curl -X POST https://[username]-[space-name].hf.space/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"password": "password123"
}'curl -X GET https://[username]-[space-name].hf.space/api/me \
-H "Authorization: Bearer <access_token>"- β DEBUG = False di production
- β ALLOWED_HOSTS = ['*'] untuk Hugging Face
- β CORS enabled untuk cross-origin requests
- β JWT tokens dengan expiry configurable
- β Supabase PostgreSQL untuk database
- Check Logs di Hugging Face dashboard
- Pastikan environment variables sudah di-set
- Pastikan Dockerfile valid
- Cek Supabase credentials
- Pastikan Supabase project active
- Pastikan connection pooler diaktifkan
- Cek
/api/schema/endpoint - Restart Space jika perlu
- Check browser console untuk errors
- β Port 7860 (Hugging Face standard)
- β Non-root user (security best practice)
- β Gunicorn dengan 2 workers
- β CORS enabled
- β DEBUG = False (production)
- β ALLOWED_HOSTS = ['*']
- β JWT Authentication
- β Supabase Connection Pooler
- β Port 6543 (pooler)
- β SSL required
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference