Overview
The videos JSON endpoint fetches the latest church service videos from YouTube and returns them as structured JSON data. This endpoint processes videos from the church’s YouTube uploads playlist, filters for service videos, parses dates from titles, and returns them sorted by date.Endpoint Details
GET
/api/videos.json
Query Parameters
This endpoint does not accept any query parameters.Response
Success Response (200 OK)
Array of video objects, sorted by date (most recent first)
YouTube video ID (used to construct video URLs and default thumbnails)
Full video title from YouTube
URL to a custom thumbnail image (if one exists for this video). When not provided, the default YouTube thumbnail is used.
Error Response (500 Internal Server Error)
Error message when video fetching fails
Response Headers
Set to
application/jsonSuccess:
public, max-age=300, stale-while-revalidate=600Error: no-cache, no-store, must-revalidateCaching Strategy
The endpoint implements intelligent caching to reduce YouTube API calls:- Cache Duration: 5 minutes (300 seconds)
- Stale-While-Revalidate: 10 minutes (600 seconds)
- Rationale: Videos don’t change frequently, so short caching improves performance while ensuring fresh data
Example Response
Example Requests
Using JavaScript Fetch
Using cURL
With Error Handling
Video Processing
The endpoint performs several processing steps:- Fetch from YouTube: Retrieves videos from the church’s uploads playlist (
UUUcLKfZo5Su6-ypmt1dkPKA) - Filter: Keeps only videos with “service” or “locc” in the title
- Exclude: Removes specific excluded video IDs (e.g., announcements, non-service content)
- Parse Dates: Extracts dates from video titles using multiple format patterns
- Sort: Orders videos by parsed date (most recent first)
- Custom Thumbnails: Applies custom thumbnail URLs for specific videos
- Return: Sends processed video data as JSON
Supported Date Formats
The endpoint can parse dates from video titles in these formats:- Numeric:
MM/DD/YYYY,MM-DD-YYYY,MMDDYY,MDDYY - Full month:
January 15, 2024,January 15 2024 - Abbreviated:
Jan 15, 2024,Jan 15 2024 - With ordinals:
January 15th, 2024,Jan 15th 2024
"LOCC | December 29, 2024"→ December 29, 2024"Service - 12/15/24"→ December 15, 2024"Church Service | Jan 1st, 2025"→ January 1, 2025
Custom Thumbnails
Videos may include acustomThumbnail field pointing to custom-designed thumbnail images hosted on the church’s CDN. These are used instead of YouTube’s auto-generated thumbnails for a consistent brand appearance.
If customThumbnail is not present, use the YouTube default:
Use Cases
- Homepage Video Grid: Display recent sermons on the church website
- Archives Page: Show chronological list of all service videos
- Search/Filter: Build custom search and filtering interfaces
- Mobile Apps: Fetch video data for native mobile applications
- Third-party Integrations: Provide video data to partner services
Implementation Details
The endpoint:- Uses the
youtube-srlibrary to fetch YouTube playlist data - Is not pre-rendered and runs at request time for fresh data
- Implements stale-while-revalidate caching for optimal performance
- Includes fallback handling if YouTube API requests fail
- Filters out non-service videos automatically
- Maintains a custom thumbnail map for specific video IDs
/home/daytona/workspace/source/src/pages/api/videos.json.ts:18