Public
Like
BingImageOfDay
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v23View latest version
This Val Town project fetches, displays, and archives the Bing Image of the Day, providing an API to access both current and historical images.
The service provides several capabilities:
- Fetch the current Bing Image of the Day
- Archive images to Val Town blob storage with date-based naming
- List all archived images with their dates
- Retrieve specific historical images by date
Endpoint | Method | Description |
---|---|---|
/ | GET | Returns the current Bing Image of the Day |
/list | GET | Returns a JSON object listing all archived images with dates as keys and URLs as values |
/get/:date | GET | Returns a specific archived image by date (format: MM-DD-YYYY) |
/backup | GET | Manually triggers a backup of the current Bing Image of the Day |
/docs | GET | Returns API documentation in JSON format |
This project consists of three main components:
- index.tsx - The main HTTP val that provides the API endpoints using the Hono framework
- fetchBingImage.tsx - A helper function that handles fetching the image from Bing
- backupImage.tsx - A helper function that handles archiving images to blob storage
- The service scrapes the Bing image from a public source (bing.gifposter.com)
- Images are stored in Val Town's blob storage with keys in the format
bing-images-of-day/MM-DD-YYYY.jpg
- The main API serves both current and archived images with proper caching headers
- Automation can be set up to trigger the backup endpoint daily to build a complete archive
GET /
Returns the current Bing Image of the Day as a JPEG with appropriate headers.
GET /list
Returns a JSON object like:
{ "1-15-2024": "https://your-val.web.val.run/get/1-15-2024.jpg", "1-14-2024": "https://your-val.web.val.run/get/1-14-2024.jpg", "1-13-2024": "https://your-val.web.val.run/get/1-13-2024.jpg" }
GET /get/1-15-2024
Returns the image for January 15, 2024 as a JPEG.
To create a complete archive, you can:
- Set up a daily cron job using Val Town's scheduling to hit the
/backup
endpoint - Use the endpoint in existing automations that run daily
- Uses TypeScript for type safety
- Implemented with the Hono framework for robust API routing
- Leverages Val Town's blob storage for image archiving
- Follows best practices for error handling and response headers
- Image source: Bing's Image of the Day via gifposter.com
- Hosted on Val Town