HeroFS REST API Server
A comprehensive REST API server for the HeroFS distributed filesystem, built with V and VEB framework.
Features
- Complete CRUD Operations for all HeroFS entities (Filesystems, Directories, Files, Blobs, Symlinks)
- Advanced Filesystem Tools (find, copy, move, remove, import/export)
- CORS Support for frontend integration
- JSON Request/Response with consistent error handling
- RESTful Design following standard HTTP conventions
- Production Ready with proper error handling and validation
Quick Start
import incubaid.herolib.hero.herofs_server
// Create and start server
mut server := herofs_server.new(
port: 8080
host: 'localhost'
cors_enabled: true
allowed_origins: ['*']
)!
server.start()!
API Endpoints
Health & Info
GET /health- Health checkGET /api- API information and available endpoints
Filesystems (/api/fs)
GET /api/fs- List all filesystemsGET /api/fs/:id- Get filesystem by IDPOST /api/fs- Create new filesystemPUT /api/fs/:id- Update filesystemDELETE /api/fs/:id- Delete filesystemGET /api/fs/:id/exists- Check if filesystem existsPOST /api/fs/:id/usage/increase- Increase usage counterPOST /api/fs/:id/usage/decrease- Decrease usage counterPOST /api/fs/:id/quota/check- Check quota availability
Directories (/api/dirs)
GET /api/dirs- List all directoriesGET /api/dirs/:id- Get directory by IDPOST /api/dirs- Create new directoryPUT /api/dirs/:id- Update directoryDELETE /api/dirs/:id- Delete directoryPOST /api/dirs/create-path- Create directory pathGET /api/dirs/:id/has-children- Check if directory has childrenGET /api/dirs/:id/children- Get directory children
Files (/api/files)
GET /api/files- List all filesGET /api/files/:id- Get file by IDPOST /api/files- Create new filePUT /api/files/:id- Update fileDELETE /api/files/:id- Delete filePOST /api/files/:id/add-to-directory- Add file to directoryPOST /api/files/:id/remove-from-directory- Remove file from directoryPOST /api/files/:id/metadata- Update file metadataPOST /api/files/:id/accessed- Update accessed timestampGET /api/files/by-filesystem/:fs_id- List files by filesystem
Blobs (/api/blobs)
GET /api/blobs- List all blobsGET /api/blobs/:id- Get blob by IDPOST /api/blobs- Create new blobPUT /api/blobs/:id- Update blobDELETE /api/blobs/:id- Delete blobGET /api/blobs/:id/content- Get blob raw contentGET /api/blobs/:id/verify- Verify blob integrity
Symlinks (/api/symlinks)
GET /api/symlinks- List all symlinksGET /api/symlinks/:id- Get symlink by IDPOST /api/symlinks- Create new symlinkPUT /api/symlinks/:id- Update symlinkDELETE /api/symlinks/:id- Delete symlinkGET /api/symlinks/:id/is-broken- Check if symlink is broken
Blob Membership (/api/blob-membership)
GET /api/blob-membership- List all blob membershipsGET /api/blob-membership/:id- Get blob membership by IDPOST /api/blob-membership- Create new blob membershipDELETE /api/blob-membership/:id- Delete blob membership
Filesystem Tools (/api/tools)
POST /api/tools/find- Find files and directoriesPOST /api/tools/copy- Copy files or directoriesPOST /api/tools/move- Move files or directoriesPOST /api/tools/remove- Remove files or directoriesPOST /api/tools/list- List directory contentsPOST /api/tools/import/file- Import file from real filesystemPOST /api/tools/import/directory- Import directory from real filesystemPOST /api/tools/export/file- Export file to real filesystemPOST /api/tools/export/directory- Export directory to real filesystemPOST /api/tools/content/:fs_id- Get file content as text
Request/Response Format
Standard Response Structure
{
"success": true,
"data": { ... },
"message": "Operation completed successfully",
"error": ""
}
Error Response Structure
{
"success": false,
"error": "Error description",
"message": "User-friendly error message"
}
Example Usage
Create a Filesystem
curl -X POST http://localhost:8080/api/fs \
-H "Content-Type: application/json" \
-d '{
"name": "my_filesystem",
"description": "My test filesystem",
"quota_bytes": 1073741824
}'
Create a Directory
curl -X POST http://localhost:8080/api/dirs \
-H "Content-Type: application/json" \
-d '{
"name": "documents",
"fs_id": 1,
"parent_id": 0,
"description": "Documents directory"
}'
Find Files
curl -X POST http://localhost:8080/api/tools/find \
-H "Content-Type: application/json" \
-d '{
"fs_id": 1,
"pattern": "*.txt",
"recursive": true
}'
Import File
curl -X POST http://localhost:8080/api/tools/import/file \
-H "Content-Type: application/json" \
-d '{
"fs_id": 1,
"real_path": "/path/to/local/file.txt",
"vfs_path": "/imported/file.txt",
"overwrite": false
}'
HTTP Status Codes
200 OK- Successful operation201 Created- Resource created successfully400 Bad Request- Invalid request format or parameters404 Not Found- Resource not found500 Internal Server Error- Server error
CORS Support
The server supports CORS for frontend integration. Configure allowed origins when creating the server:
mut server := herofs_server.new(
cors_enabled: true
allowed_origins: ['http://localhost:3000', 'https://myapp.com']
)!
Error Handling
The API provides comprehensive error handling with:
- Input validation for all parameters
- Proper HTTP status codes
- Detailed error messages
- Consistent error response format
Integration with HeroFS
The server integrates seamlessly with the HeroFS module, providing:
- Full access to all HeroFS functionality
- Proper factory pattern usage
- Data integrity through BLAKE3 hashing
- Efficient Redis-based storage
- Complete filesystem operations
Production Deployment
For production use:
- Configure appropriate CORS origins
- Set up proper logging
- Configure Redis connection
- Set appropriate quotas and limits
- Monitor server performance
The server is designed to be production-ready with proper error handling, validation, and performance considerations.