API Reference
Complete reference for MegaVault's REST API endpoints, authentication, and integration guides.
Table of Contents
API Overview
MegaVault provides a comprehensive REST API for file management, user authentication, and system integration. The API is designed for both web and mobile applications.
REST Architecture
Standard HTTP methods
- ✅ RESTful design principles
- ✅ Standard HTTP status codes
- ✅ JSON request/response format
- ✅ Consistent URL patterns
Authentication
Secure access control
- ✅ JWT token-based auth
- ✅ Session management
- ✅ API key support
- ✅ Role-based permissions
Developer Experience
Easy integration
- ✅ Comprehensive documentation
- ✅ Code examples
- ✅ SDKs and libraries
- ✅ Interactive testing
API Base URL
https://your-domain.com/apiAuthentication
MegaVault uses JWT tokens for API authentication. Include the token in the Authorization header.
Authorization: Bearer YOUR_JWT_TOKENGetting an Access Token
POST /api/auth/signin
Content-Type: application/json
{
"email": "user@example.com",
"password": "your-password"
}{
"success": true,
"user": {
"id": "user_123",
"email": "user@example.com",
"name": "John Doe"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": "24h"
}Endpoint Categories
The MegaVault API is organized into logical categories for different functionalities.
Authentication Endpoints
POST /api/auth/signin- User loginPOST /api/auth/signup- User registrationPOST /api/auth/signout- User logoutGET /api/auth/session- Get session
File Management
GET /api/files- List filesPOST /api/files/upload- Upload fileGET /api/files/:id- Get file infoDELETE /api/files/:id- Delete file
User Management
GET /api/users/profile- Get profilePUT /api/users/profile- Update profileGET /api/users/usage- Get usage statsPUT /api/users/settings- Update settings
Mobile Endpoints
POST /api/mobile/auth- Mobile authPOST /api/mobile/upload- Mobile uploadGET /api/mobile/sync- Data syncPOST /api/mobile/push- Push notifications
Request Format
All API requests should follow these formatting guidelines for consistency.
Headers
Content-Type: application/json
Authorization: Bearer YOUR_JWT_TOKEN
User-Agent: YourApp/1.0Query Parameters
GET /api/files?page=1&limit=20&sort=createdAt&order=descRequest Body
{
"name": "document.pdf",
"folder": "/documents",
"tags": ["important", "work"],
"metadata": {
"description": "Project specification document"
}
}Response Format
All API responses follow a consistent format with proper HTTP status codes.
Success Response
{
"success": true,
"data": {
"id": "file_123",
"name": "document.pdf",
"size": 1024,
"createdAt": "2024-01-15T10:30:00Z"
},
"meta": {
"page": 1,
"limit": 20,
"total": 50
}
}Error Response
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid file format",
"details": {
"field": "file",
"allowedTypes": ["pdf", "jpg", "png"]
}
}
}HTTP Status Codes
| Status Code | Meaning | Usage |
|---|---|---|
| 200 | OK | Request successful |
| 201 | Created | Resource created successfully |
| 400 | Bad Request | Invalid request format or parameters |
| 401 | Unauthorized | Authentication required or invalid |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource does not exist |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server-side error occurred |
Rate Limiting
API endpoints are rate-limited to ensure fair usage and system stability.
| Endpoint Category | Rate Limit | Window |
|---|---|---|
| Authentication | 5 requests | 1 minute |
| File Operations | 100 requests | 1 hour |
| File Upload | 10 uploads | 1 hour |
| General API | 1000 requests | 1 hour |
Rate Limit Headers
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200Error Handling
Proper error handling is essential for robust API integration.
Common Error Codes
Client Errors (4xx)
- VALIDATION_ERROR: Invalid input data
- AUTHENTICATION_FAILED: Invalid credentials
- INSUFFICIENT_PERMISSIONS: Access denied
- RESOURCE_NOT_FOUND: Requested resource missing
Server Errors (5xx)
- INTERNAL_ERROR: Unexpected server error
- DATABASE_ERROR: Database connection issue
- STORAGE_ERROR: File storage problem
- SERVICE_UNAVAILABLE: Temporary service issue
Error Handling Best Practices
- Check Status Codes: Always check HTTP status codes
- Parse Error Messages: Extract meaningful error details
- Implement Retry Logic: Retry on 5xx errors with backoff
- Handle Rate Limits: Respect rate limit headers
- Log Errors: Log errors for debugging and monitoring
SDK Availability
API Endpoints
Authentication →
User authentication and session management
File Management →
Upload, download, and manage files
User Management →
User profiles and account settings
Mobile Endpoints →
Mobile-specific API endpoints
Error Handling →
Error codes and troubleshooting
Rate Limiting →
API rate limiting and best practices