REST API¶
rninja-cached server REST API reference.
Optional Feature
REST API is an optional interface. The primary protocol is NNG/MessagePack for performance.
Base URL¶
Authentication¶
All requests require authentication via bearer token:
Or via query parameter:
Endpoints¶
Health Check¶
Response:
Cache Operations¶
Get Entry¶
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | Cache key (64 hex chars) |
Response:
200 OK: Entry found, body contains artifact404 Not Found: Entry not in cache401 Unauthorized: Invalid token
Headers:
Put Entry¶
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | Cache key (64 hex chars) |
Request body: artifact data (binary)
Headers:
Response:
201 Created: Entry stored409 Conflict: Entry already exists413 Payload Too Large: Entry exceeds size limit401 Unauthorized: Invalid token
Delete Entry¶
Response:
204 No Content: Entry deleted404 Not Found: Entry not found401 Unauthorized: Invalid token
Check Entry¶
Response:
200 OK: Entry exists404 Not Found: Entry not found
Headers on success:
Statistics¶
Get Stats¶
Response:
{
"total_entries": 12345,
"total_size": 5368709120,
"hits": 98765,
"misses": 4321,
"hit_rate": 0.958,
"gets_per_second": 150.5,
"puts_per_second": 25.3,
"uptime_seconds": 86400
}
Get Detailed Stats¶
Response:
{
"cache": {
"entries": 12345,
"size_bytes": 5368709120,
"max_size_bytes": 107374182400
},
"operations": {
"gets": 103086,
"puts": 12345,
"deletes": 123,
"hits": 98765,
"misses": 4321
},
"performance": {
"avg_get_latency_ms": 5.2,
"avg_put_latency_ms": 12.8,
"p99_get_latency_ms": 25.0,
"p99_put_latency_ms": 50.0
},
"connections": {
"active": 42,
"total": 98765
}
}
Administration¶
Trigger Garbage Collection¶
Request:
Response:
Clear Cache¶
Destructive
This removes all cached entries.
Response:
Get Configuration¶
Response:
{
"storage": {
"backend": "filesystem",
"path": "/var/cache/rninja",
"max_size": "100G"
},
"auth": {
"mode": "token"
},
"server": {
"bind": "0.0.0.0:9877",
"workers": 8
}
}
Error Responses¶
All errors return JSON:
Error codes:
| Code | HTTP Status | Description |
|---|---|---|
not_found |
404 | Entry not found |
unauthorized |
401 | Invalid or missing token |
forbidden |
403 | Token lacks permission |
bad_request |
400 | Invalid request |
conflict |
409 | Entry already exists |
too_large |
413 | Payload too large |
internal_error |
500 | Server error |
Rate Limiting¶
Responses include rate limit headers:
Examples¶
cURL¶
# Get entry
curl -H "Authorization: Bearer $TOKEN" \
https://cache.example.com:9877/api/v1/cache/abc123...
# Put entry
curl -X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @artifact.bin \
https://cache.example.com:9877/api/v1/cache/abc123...
# Get stats
curl -H "Authorization: Bearer $TOKEN" \
https://cache.example.com:9877/api/v1/stats
Python¶
import requests
BASE_URL = "https://cache.example.com:9877/api/v1"
TOKEN = "your-token"
headers = {"Authorization": f"Bearer {TOKEN}"}
# Get entry
response = requests.get(f"{BASE_URL}/cache/{key}", headers=headers)
if response.status_code == 200:
artifact = response.content
# Put entry
response = requests.put(
f"{BASE_URL}/cache/{key}",
headers={**headers, "Content-Type": "application/octet-stream"},
data=artifact_data
)
# Get stats
response = requests.get(f"{BASE_URL}/stats", headers=headers)
stats = response.json()
OpenAPI Specification¶
Full OpenAPI 3.0 spec available at: