Base URL: http://localhost:3000
Returns the gateway landing page.
Response:
200 OK- HTML landing page
Health check endpoint.
Response:
{
"status": "healthy",
"uptime_seconds": 3600,
"version": "0.1.0"
}Status Codes:
200 OK- Gateway is healthy503 Service Unavailable- Gateway is unhealthy
Prometheus-compatible metrics endpoint.
Response:
{
"requests_total": 1000,
"requests_success": 950,
"requests_error": 50,
"bytes_served": 104857600,
"cache_hits": 800,
"cache_misses": 200,
"uptime_seconds": 3600
}Retrieve content by Content ID.
Parameters:
| Name | Type | Description |
|---|---|---|
cid |
path | Content identifier (BLAKE3 hash) |
Headers:
| Name | Description |
|---|---|
Range |
Optional byte range for partial content |
Response:
200 OK- Content bytes206 Partial Content- Partial content (with Range header)404 Not Found- Content not found504 Gateway Timeout- Content retrieval timed out
Response Headers:
Content-Type: application/octet-stream
Content-Length: 1024
X-Content-Hash: abc123...
Example:
curl http://localhost:3000/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdGUpload content to the network.
Request:
Content-Type: application/octet-streamormultipart/form-data- Body: Raw content bytes or file upload
Response:
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"size": 1024,
"fragments": 4,
"status": "uploaded"
}Status Codes:
201 Created- Content uploaded successfully400 Bad Request- Invalid content413 Payload Too Large- Content exceeds size limit500 Internal Server Error- Upload failed
Example:
curl -X POST \
-H "Content-Type: application/octet-stream" \
--data-binary @myfile.txt \
http://localhost:3000/uploadGet status of content in the network.
Parameters:
| Name | Type | Description |
|---|---|---|
cid |
path | Content identifier |
Response:
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"size": 1024,
"fragments": 4,
"providers": 3,
"replication_status": "healthy",
"created_at": "2024-01-15T10:30:00Z"
}Status Codes:
200 OK- Status retrieved404 Not Found- Content not found
Pin content to prevent garbage collection.
Parameters:
| Name | Type | Description |
|---|---|---|
cid |
path | Content identifier to pin |
Response:
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"pinned": true
}Unpin content.
Parameters:
| Name | Type | Description |
|---|---|---|
cid |
path | Content identifier to unpin |
Response:
{
"cid": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG",
"pinned": false
}Base URL: http://localhost:8080
Get node status.
Response:
{
"node_id": "12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp",
"uptime_seconds": 7200,
"peers_connected": 15,
"content_count": 42,
"storage_used_bytes": 1073741824,
"storage_max_bytes": 10737418240
}List connected peers.
Response:
{
"peers": [
{
"peer_id": "12D3KooW...",
"addresses": ["/ip4/192.168.1.100/tcp/4001"],
"state": "connected",
"score": 85.5,
"latency_ms": 45
}
],
"total": 15
}List stored content.
Response:
{
"content": [
{
"cid": "Qm...",
"size": 1024,
"pinned": true,
"replicas": 3,
"created_at": "2024-01-15T10:30:00Z"
}
],
"total": 42
}Get bandwidth statistics.
Response:
{
"inbound": {
"total_bytes": 1073741824,
"rate_bps": 1048576
},
"outbound": {
"total_bytes": 2147483648,
"rate_bps": 2097152
},
"by_peer": [
{
"peer_id": "12D3KooW...",
"inbound_bytes": 104857600,
"outbound_bytes": 209715200
}
]
}Main client for interacting with ShadowMesh.
import { ShadowMeshClient, ClientConfig } from '@shadowmesh/sdk';
const config: ClientConfig = {
gatewayUrl: 'http://localhost:3000',
timeout: 30000,
retries: 3,
encryption: {
enabled: true,
algorithm: 'ChaCha20-Poly1305'
}
};
const client = new ShadowMeshClient(config);Deploy content to the network.
const content = new TextEncoder().encode('Hello, World!');
const result = await client.deploy(content, {
encrypt: true,
pin: true,
metadata: { name: 'greeting.txt' }
});
console.log(result.cid); // Content ID
console.log(result.size); // Size in bytesRetrieve content by CID.
const content = await client.retrieve('Qm...', {
decrypt: true,
verify: true
});
const text = new TextDecoder().decode(content);Get content status.
const status = await client.status('Qm...');
console.log(status.providers); // Number of providers
console.log(status.healthy); // Replication healthPin content.
await client.pin('Qm...');Unpin content.
await client.unpin('Qm...');Get network statistics.
const stats = await client.stats();
console.log(stats.totalRequests);
console.log(stats.bytesTransferred);Browser-compatible cryptographic operations.
import { CryptoProvider } from '@shadowmesh/sdk';
const crypto = new CryptoProvider();Generate a new encryption key.
const key = await crypto.generateKey();Encrypt data.
const encrypted = await crypto.encrypt(data, key);Decrypt data.
const decrypted = await crypto.decrypt(encrypted, key);Hash content.
const hash = await crypto.hash(data);Storage backends for persisting content.
import { MemoryStorage, IndexedDBStorage } from '@shadowmesh/sdk';
// In-memory storage (for testing)
const memoryStorage = new MemoryStorage();
// IndexedDB storage (for browser)
const indexedStorage = new IndexedDBStorage('shadowmesh-cache');Get content by key.
Store content.
Delete content.
Check if content exists.
Clear all content.
Get storage statistics.
LRU cache with TTL support.
import { ContentCache } from '@shadowmesh/sdk';
const cache = new ContentCache({
maxSize: 100 * 1024 * 1024, // 100MB
ttl: 3600000, // 1 hour
storage: new MemoryStorage()
});Get cached content.
Cache content.
Invalidate cache entry.
Clear entire cache.
| Code | Name | Description |
|---|---|---|
1001 |
NETWORK_ERROR |
Network request failed |
1002 |
TIMEOUT |
Request timed out |
1003 |
NOT_FOUND |
Content not found |
1004 |
INVALID_CID |
Invalid content identifier |
2001 |
ENCRYPTION_FAILED |
Encryption operation failed |
2002 |
DECRYPTION_FAILED |
Decryption operation failed |
2003 |
HASH_MISMATCH |
Content hash verification failed |
3001 |
STORAGE_FULL |
Storage quota exceeded |
3002 |
STORAGE_ERROR |
Storage operation failed |
Default rate limits (configurable):
| Endpoint | Limit |
|---|---|
GET /:cid |
100 req/min |
POST /upload |
10 req/min |
GET /status/:cid |
60 req/min |
Rate limit headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1705312800
Supported content types with automatic detection:
| Type | Extension | MIME Type |
|---|---|---|
| Text | .txt |
text/plain |
| HTML | .html |
text/html |
| JSON | .json |
application/json |
| Image | .png, .jpg |
image/* |
| Video | .mp4, .webm |
video/* |
| Binary | * |
application/octet-stream |