Usage Guide¶
Complete guide for local development, testing, and production usage of the Micro-Learning Platform API.
Table of Contents¶
- Overview
- Local Development
- Testing with api.http
- Production Usage
- Multi-Function Architecture
- Authentication
- Quick Reference
Overview¶
The Micro-Learning Platform API is deployed as multiple independent Supabase Edge Functions, each handling specific functionality. This architecture provides:
- ✅ Independent Telemetry: Each function has its own metrics and logs
- ✅ Selective Deployment: Deploy only the functions that changed
- ✅ Better Isolation: Errors in one function don't affect others
- ✅ Easier Testing: Test functions independently
- ✅ Scalability: Scale functions based on usage patterns
Function Overview¶
| Function | Purpose | Key Endpoints |
|---|---|---|
| browse | Content browsing | /api/v1/domains, /api/v1/trails, /api/v1/concepts, /api/v1/sparks, /api/v1/beacons |
| search | Search & autocomplete | /api/v1/search, /api/v1/autocomplete |
| discovery | Discovery/experience APIs | /api/v1/discovery/domains, /api/v1/discovery/trails, /api/v1/discovery/concepts |
| graph | Knowledge graph operations | /api/v1/graph/*, /api/v1/path |
| user | User profile & progress | /api/v1/me/*, /api/v1/me/journeys, /api/v1/me/events |
| metadata | Metadata enumerations | /api/v1/metadata |
| snapshots | Content versioning | /api/v1/snapshots |
Local Development¶
Prerequisites¶
- Docker: Running (Docker Desktop or Colima)
- Deno: Installed (v1.40+)
- Supabase CLI: Installed (
npm install -g supabase)
Quick Start¶
# 1. Start Supabase (includes PostgreSQL, Auth, etc.)
supabase start
# 2. Setup testing environment
deno task setup:e2e # Creates test user, updates api.http
# 3. Start API server
deno task dev
Access Points: - API Server: http://localhost:8000 - API Docs (Swagger): http://localhost:8000/doc - Supabase Studio: http://127.0.0.1:54323
Development Server (Recommended)¶
Best for: Development, debugging, hot reload
Advantages:
- ✅ Hot reload on file changes
- ✅ Structured JSON logs
- ✅ Easy debugging
- ✅ Single unified API at http://localhost:8000
- ✅ All endpoints available at /api/v1/*
Usage:
# All endpoints available at:
curl http://localhost:8000/api/v1/domains
curl http://localhost:8000/api/v1/search?q=test
curl http://localhost:8000/api/v1/me # Requires auth
Edge Functions (Production-like Testing)¶
Best for: Testing production deployment, edge function behavior
# Start Supabase first
supabase start
# Serve individual functions
supabase functions serve browse
supabase functions serve search
supabase functions serve discovery
# ... etc
# Or serve all at once
deno task serve:functions all
Function URLs:
- Browse: http://127.0.0.1:54321/functions/v1/browse
- Search: http://127.0.0.1:54321/functions/v1/search
- Discovery: http://127.0.0.1:54321/functions/v1/discovery
- User: http://127.0.0.1:54321/functions/v1/user
- Graph: http://127.0.0.1:54321/functions/v1/graph
- Metadata: http://127.0.0.1:54321/functions/v1/metadata
- Snapshots: http://127.0.0.1:54321/functions/v1/snapshots
Important: When using edge functions, the path includes /api/v1/:
- ✅ Correct: http://127.0.0.1:54321/functions/v1/browse/api/v1/domains
- ❌ Wrong: http://127.0.0.1:54321/functions/v1/browse/domains
Environment Setup¶
-
Get Supabase credentials:
-
Create
.envfile: -
Edit
.env: -
Initialize database:
Testing with api.http¶
The api.http file provides a convenient way to test all API endpoints using VS Code's REST Client extension.
Setup¶
- Install REST Client Extension:
- Open VS Code
- Go to Extensions (Cmd+Shift+X / Ctrl+Shift+X)
- Search for "REST Client" by Huachao Mao
-
Install it
-
Get Authentication Token:
For Local Development:
This automatically: - Creates a test user (test@example.com / test123456)
- Gets a JWT token from local Supabase
- Updates api.http with the token
For Production:
Or with arguments: This automatically: - Authenticates with production Supabase - Gets a production JWT token - Updatesapi.http with production URLs and token
- Refresh Token (when expired):
Using api.http¶
-
Open
api.httpin VS Code -
Configure Base URL:
- Local Development Server: Uncomment
@baseUrl = http://localhost:8000 - Local Edge Functions: Use function-specific URLs:
-
Production: Use production URLs (auto-updated by
setup:production) -
Send Requests:
- Click "Send Request" above any request
-
Or use keyboard shortcut:
- Mac:
Cmd+Option+R - Windows/Linux:
Ctrl+Alt+R
- Mac:
-
Test Authenticated Endpoints:
- Ensure
@authTokenis set (rundeno task setup:e2eordeno task setup:production) - Requests with
Authorization: Bearer {{authToken}}will automatically use the token
Example Requests¶
Public Endpoints (no auth required):
### Discover domains (public - no auth required)
GET {{discoveryUrl}}/api/v1/discovery/domains
### Discover trails (public - no auth required)
GET {{discoveryUrl}}/api/v1/discovery/trails
### Get metadata (public - no auth required)
GET {{metadataUrl}}/api/v1/metadata
Authenticated Endpoints (require JWT token):
### List domains (authenticated)
GET {{browseUrl}}/api/v1/domains
Authorization: Bearer {{authToken}}
### Search content (authenticated)
GET {{searchUrl}}/api/v1/search?q=machine learning
Authorization: Bearer {{authToken}}
### Get user profile (authenticated)
GET {{userUrl}}/api/v1/me
Authorization: Bearer {{authToken}}
### List user journeys (authenticated)
GET {{userUrl}}/api/v1/me/journeys
Authorization: Bearer {{authToken}}
For complete authentication documentation, see Authentication Guide.
Health Checks:
### Check all functions
GET {{browseUrl}}/health
GET {{searchUrl}}/health
GET {{discoveryUrl}}/health
GET {{userUrl}}/health
GET {{graphUrl}}/health
GET {{metadataUrl}}/health
GET {{snapshotsUrl}}/health
Function-Specific Testing¶
When testing with edge functions (local or production), use function-specific URLs:
### Browse Function (requires auth)
GET {{browseUrl}}/api/v1/domains
Authorization: Bearer {{authToken}}
GET {{browseUrl}}/api/v1/trails
Authorization: Bearer {{authToken}}
GET {{browseUrl}}/api/v1/concepts
Authorization: Bearer {{authToken}}
### Search Function (requires auth)
GET {{searchUrl}}/api/v1/search?q=test
Authorization: Bearer {{authToken}}
GET {{searchUrl}}/api/v1/search/autocomplete?q=neural
Authorization: Bearer {{authToken}}
### Discovery Function (public - no auth required)
GET {{discoveryUrl}}/api/v1/discovery/domains
GET {{discoveryUrl}}/api/v1/discovery/trails
### Graph Function (requires auth)
GET {{graphUrl}}/api/v1/graph/sparks/intro-to-neural-nets
Authorization: Bearer {{authToken}}
### Snapshots Function (requires auth)
GET {{snapshotsUrl}}/api/v1/snapshots
Authorization: Bearer {{authToken}}
### Metadata Function (public - no auth required)
GET {{metadataUrl}}/api/v1/metadata
### User Function (requires auth)
GET {{userUrl}}/api/v1/me
Authorization: Bearer {{authToken}}
Production Usage¶
Getting Production Credentials¶
- Get Project Reference:
- Go to https://supabase.com/dashboard
- Select your project
- Go to Settings > General
-
Copy the "Reference ID"
-
Get API Keys:
- Go to Settings > API
- Copy the "anon" key (for client-side)
- Copy the "service_role" key (for server-side, keep secret!)
Setting Up Production Testing¶
- Get Production Token: Follow the prompts to enter:
- Email (of a user in production)
- Password
-
Project reference ID (or Supabase URL)
-
Or use environment variables:
-
Or use command-line arguments:
-
Verify api.http is updated:
- Check that
@authTokenhas a production token - Check that function URLs point to production
- Test a health endpoint:
GET {{browseUrl}}/health
Production Endpoints¶
All production endpoints follow this pattern:
Examples:
- Browse domains: https://xxx.supabase.co/functions/v1/browse/api/v1/domains
- Search: https://xxx.supabase.co/functions/v1/search/api/v1/search?q=test
- User profile: https://xxx.supabase.co/functions/v1/user/api/v1/me
Function URLs¶
Production Base URLs:
https://<project-ref>.supabase.co/functions/v1/browse
https://<project-ref>.supabase.co/functions/v1/search
https://<project-ref>.supabase.co/functions/v1/discovery
https://<project-ref>.supabase.co/functions/v1/user
https://<project-ref>.supabase.co/functions/v1/graph
https://<project-ref>.supabase.co/functions/v1/metadata
https://<project-ref>.supabase.co/functions/v1/snapshots
Authentication in Production¶
- For Public Endpoints (no authentication required):
- Only discovery and metadata endpoints are public
- Examples:
/api/v1/discovery/domains/api/v1/discovery/trails/api/v1/discovery/concepts/api/v1/metadata
-
Can be accessed without
Authorizationheader -
For Authenticated Endpoints (require JWT token):
- All other endpoints require authentication
- Requires
Authorization: Bearer <token>header - Token must be a valid Supabase JWT
- Get token via
deno task setup:productionor Supabase Auth API - Examples:
/api/v1/domains(browse function)/api/v1/trails(browse function)/api/v1/search(search function)/api/v1/graph/*(graph function)/api/v1/snapshots/*(snapshots function)/api/v1/me/*(user function)
For detailed authentication documentation, see Authentication Guide.
- Token Expiration:
- Tokens expire after 1 hour
- Refresh by running
deno task setup:productionagain - Or implement token refresh in your application
Deploying Functions¶
# Deploy all functions
deno task deploy:all
# Deploy specific function
deno task deploy:browse
deno task deploy:search
deno task deploy:discovery
deno task deploy:user
deno task deploy:graph
deno task deploy:metadata
deno task deploy:snapshots
# Deploy only changed functions
deno task deploy:changed
# Check deployment status
supabase functions list
# View function logs
supabase functions logs browse
supabase functions logs search
# etc.
# Check function health
deno task check:functions --project-ref <ref>
For detailed deployment instructions, see DEPLOYMENT_GUIDE.md.
Multi-Function Architecture¶
Why Multiple Functions?¶
The API is split into multiple independent functions for:
- Independent Telemetry: Each function has its own metrics and logs
- Selective Deployment: Deploy only the functions that changed
- Better Isolation: Errors in one function don't affect others
- Easier Testing: Test functions independently
- Scalability: Scale functions based on usage patterns
Function Responsibilities¶
browse - Content browsing and navigation - Domains, trails, concepts, sparks, beacons - Entity relationships and navigation - Content details and metadata
search - Search and discovery - Full-text search across all content - Autocomplete suggestions - Search facets and filters
discovery - Discovery/experience APIs - Aggregated domain views with trails - Trail views with concepts - Concept views with sparks
graph - Knowledge graph operations - Prerequisite relationships - Learning path calculations - Graph traversal and queries
user - User profile and progress - User profile management - Learning journeys - Learning events and milestones - User statistics
metadata - Metadata enumerations - Difficulty levels - Link types - Journey statuses - Learning verbs - Beacon categories
snapshots - Content versioning - Snapshot management - Historical content access - Version comparison
Function URLs Structure¶
Local Development:
Production:
Development Server (unified):
Health Checks¶
Each function has its own health endpoint:
# Local
curl http://127.0.0.1:54321/functions/v1/browse/health
curl http://127.0.0.1:54321/functions/v1/search/health
# etc.
# Production
curl https://<project-ref>.supabase.co/functions/v1/browse/health
curl https://<project-ref>.supabase.co/functions/v1/search/health
# etc.
# Check all functions
deno task check:functions --local # Local
deno task check:functions --project-ref <ref> # Production
Swagger UI¶
Each function has its own Swagger UI:
Local:
- Browse: http://127.0.0.1:54321/functions/v1/browse/doc
- Search: http://127.0.0.1:54321/functions/v1/search/doc
- etc.
Production:
- Browse: https://<project-ref>.supabase.co/functions/v1/browse/doc
- Search: https://<project-ref>.supabase.co/functions/v1/search/doc
- etc.
Development Server:
- Unified: http://localhost:8000/doc
Authentication¶
Getting a JWT Token¶
Local Development:
- Creates test user:test@example.com / test123456
- Gets JWT token from local Supabase
- Updates api.http automatically
Production:
- Authenticates with production Supabase - Gets production JWT token - Updatesapi.http with production URLs and token
Manual (via Supabase Auth API):
curl -X POST 'https://<project-ref>.supabase.co/auth/v1/token?grant_type=password' \
-H "apikey: YOUR_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password"}'
Using Authentication¶
In api.http:
In curl:
curl -H "Authorization: Bearer <token>" \
https://<project-ref>.supabase.co/functions/v1/user/api/v1/me
In JavaScript/TypeScript:
const response = await fetch('https://xxx.supabase.co/functions/v1/user/api/v1/me', {
headers: {
'Authorization': `Bearer ${token}`
}
});
Token Refresh¶
Tokens expire after 1 hour. Refresh by:
Or implement automatic token refresh in your application using Supabase's refresh token mechanism.
Quick Reference¶
Local Development Workflow¶
# 1. Start services
supabase start
# 2. Setup testing
deno task setup:e2e
# 3. Start API
deno task dev # Development server
# OR
supabase functions serve browse # Edge function
# 4. Test
# Open api.http in VS Code and click "Send Request"
# Or use Swagger UI: http://localhost:8000/doc
Production Workflow¶
# 1. Get production token
deno task setup:production
# 2. Test production endpoints
# Open api.http in VS Code and use function-specific URLs
# 3. Deploy functions
deno task deploy:all
# 4. Monitor
supabase functions logs browse
deno task check:functions --project-ref <ref>
Common Commands¶
# Setup
deno task setup:e2e # Local testing setup
deno task setup:production # Production token setup
# Development
deno task dev # Start dev server
deno task serve:functions all # Serve all edge functions
# Deployment
deno task deploy:all # Deploy all functions
deno task deploy:browse # Deploy specific function
deno task deploy:changed # Deploy only changed functions
# Testing
deno task check:functions --local # Check local functions
deno task check:functions --project-ref <ref> # Check production functions
deno task test:e2e # Run E2E tests
# Token Management
deno task api:token # Refresh local token
deno task setup:production # Refresh production token
Environment Variables¶
Local Development (.env):
SUPABASE_URL=http://127.0.0.1:54321
SUPABASE_ANON_KEY=<from supabase start>
SUPABASE_SERVICE_ROLE_KEY=<from supabase start>
Production:
SUPABASE_URL=https://<project-ref>.supabase.co
SUPABASE_ANON_KEY=<from Supabase Dashboard>
SUPABASE_SERVICE_ROLE_KEY=<from Supabase Dashboard>
SUPABASE_PROJECT_REF=<project-ref>
Next Steps¶
- API Testing: Use the Swagger UI or
api.httpfile - Database Exploration: Use Supabase Studio at http://127.0.0.1:54323
- API Usage: See Developer Guide for integration examples
- Deployment: See Deployment Guide for production deployment
- Logging: See Logging Guide for log format and filtering
- Troubleshooting: See Troubleshooting Guide for common issues