This project provides REST APIs to manage video files. Users can upload, trim, merge, and share video files via secure endpoints. It supports link sharing with time-based expiry and includes size and duration validation for uploaded videos.
- 📤 Video Upload: Upload video files with configurable size and duration limits.
 - ✂️ Video Trimming: Trim videos from the start or end.
 - 🔗 Video Merging: Merge multiple videos into a single file.
 - 🕒 Link Sharing: Generate sharable links for videos with time-based expiry.
 - 🔒 Authentication: API calls require a static token for security.
 
- Node.js: JavaScript runtime for building scalable server-side applications.
 - Express.js: Web framework for API development.
 - SQLite: Lightweight relational database for storing video metadata.
 - Prisma: ORM for database management and query building.
 - FFmpeg: Multimedia framework for video processing.
 - Multer: Middleware for handling file uploads.
 - Jest: Testing framework for unit and integration tests.
 
- 🖥 Node.js (v14 or later)
 - 📦 npm (Node package manager)
 
- 
Clone the repository:
git clone https://github.com/raghavg27/rest-apis-video-files.git cd rest-apis-video-files - 
Install dependencies:
npm install
 - 
Set up the database:
npx prisma migrate dev --name init
 - 
Create the
uploads/directory for video files:mkdir uploads
 - 
Create a
.envfile in the project root and add the following variables:VALID_TOKENS=videoverse # Static token for API authentication - 
Start the server:
npm start
 
The server will run on http://localhost:9000.
Import Postman collection for API docs: rest-apis-video-files.postman_collection.json
- URL: 
POST /videos/upload - Description: Upload a video file.
 - Headers: 
Authorization: your_static_api_token - Body (form-data): 
video(file) - Response:
- ✅ 
201 Created: Video uploaded successfully. ⚠️ 400 Bad Request: File missing, exceeds size limits, or duration invalid.
 - ✅ 
 
- URL: 
POST /videos/trim - Description: Trim a video from the start or end.
 - Headers: 
Authorization: your_static_api_token - Body (JSON):
{ "videoId": 1, "trimFrom": "start", "trimDuration": 10 } - Response:
- ✅ 
200 OK: Video trimmed successfully. ⚠️ 400 Bad Request: Missing or invalid parameters.
 - ✅ 
 
- URL: 
POST /videos/merge - Description: Merge multiple video files.
 - Headers: 
Authorization: your_static_api_token - Body (JSON):
{ "videoIds": [1, 2, 3] } - Response:
- ✅ 
200 OK: Videos merged successfully. ⚠️ 404 Not Found: One or more videos not found.
 - ✅ 
 
- URL: 
POST /videos/share - Description: Generate a sharable link for a video with expiry.
 - Headers: 
Authorization: your_static_api_token - Body (JSON):
{ "videoId": 1, "expiryHours": 24 } - Response:
- ✅ 
200 OK: Link generated successfully. ⚠️ 404 Not Found: Video not found.
 - ✅ 
 
- URL: 
GET /videos/shared/:token - Description: Access a shared video using its token.
 - Response:
- ✅ 
200 OK: Shared video details. ⚠️ 404 Not Found: Invalid or expired token.- ⏳ 
410 Gone: Link has expired. 
 - ✅ 
 
This project uses Jest for testing. To run the tests:
npm test- Unit Tests: Validate individual utility functions.
 - Integration Tests: Test API endpoints with mock inputs.