API Reference¶
REST API endpoints for Tinko.
Base URL¶
Authentication¶
Most endpoints require Django session authentication.
Login via:
curl -X POST http://localhost:8000/admin/login/ \
-d "username=admin&password=yourpassword&csrfmiddlewaretoken=<token>"
Core Endpoints¶
Plugin Management¶
List Plugins¶
Response:
{
"plugins": [
{
"id": "edupi.activity_timer",
"name": "Activity Timer",
"enabled": true,
"version": "1.0.0"
}
]
}
Toggle Plugin¶
POST /admin/plugins/api/toggle/
Content-Type: application/json
{
"plugin_id": "edupi.activity_timer",
"enabled": true
}
Settings¶
Get Settings¶
Response:
Save Settings¶
POST /settings/api/save/
Content-Type: application/json
{
"namespace": "edupi.activity_timer",
"settings": {
"default_duration": 15,
"led_brightness": 80
}
}
Plugin-Specific Endpoints¶
Activity Timer¶
Get Timer Status¶
Response:
Start Timer¶
POST /plugins/edupi/activity_timer/api/start/
Content-Type: application/json
{
"duration": 600,
"preset_id": "break_time"
}
Pause Timer¶
Stop Timer¶
Noise Monitor¶
Get Current Level¶
Response:
Get Historical Data¶
Response:
Update Profile¶
POST /plugins/edupi/noise_monitor/api/profile/
Content-Type: application/json
{
"profile_id": "custom",
"yellow_threshold": 40,
"red_threshold": 70
}
Routines¶
List Routines¶
Response:
{
"routines": [
{
"id": 1,
"title": "Hand Warming Exercise",
"category": "Warm-up",
"duration": 30
}
]
}
Get Routine Status¶
Response:
Control Playback¶
POST /plugins/edupi/routines/api/control/
Content-Type: application/json
{
"action": "play|pause|next|previous|stop",
"routine_id": 1
}
Touch Piano¶
Get Piano Status¶
Response:
Simulate Key Press (for testing)¶
POST /plugins/edupi/touch_piano/api/key/
Content-Type: application/json
{
"key": 1,
"pressed": true
}
WebSocket Endpoints¶
WebSocket connections for real-time updates.
Connection URL¶
Noise Monitor WebSocket¶
const ws = new WebSocket('ws://localhost:8000/ws/noise-monitor/');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Noise level:', data.instant);
};
Message Format:
Routines WebSocket¶
const ws = new WebSocket('ws://localhost:8000/ws/routines/');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'line_changed') {
console.log('Current line:', data.line_number);
}
};
Message Types:
- line_changed: New line highlighted
- playback_state: Play/pause/stop updates
- sync: Full state sync
Error Responses¶
400 Bad Request¶
401 Unauthorized¶
403 Forbidden¶
404 Not Found¶
500 Internal Server Error¶
Rate Limiting¶
Default rate limits: - 100 requests per minute per IP - WebSocket: 10 messages per second
Headers:
CORS¶
Cross-Origin requests allowed from: - Same origin - Configured in settings
Enable CORS for external access:
Plugin Development¶
Create custom API endpoints in your plugin:
# urls.py
from django.urls import path
from . import views
urlpatterns = [
path('api/data/', views.APIView.as_view()),
]
# views.py
from django.http import JsonResponse
from django.views import View
class APIView(View):
def get(self, request):
data = {'message': 'Hello from plugin!'}
return JsonResponse(data)
Testing API¶
Using curl¶
# Get status
curl http://localhost:8000/plugins/edupi/activity_timer/api/status/
# Start timer
curl -X POST http://localhost:8000/plugins/edupi/activity_timer/api/start/ \
-H "Content-Type: application/json" \
-d '{"duration": 300}'
Using Python requests¶
import requests
# Get noise level
response = requests.get(
'http://localhost:8000/plugins/edupi/noise_monitor/api/level/'
)
data = response.json()
print(f"Noise: {data['instant']} dB")
See Also¶
- WebSocket - WebSocket implementation
- Plugin Development - Create endpoints
- Configuration - API settings