FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
lightweight

lightweight

bragreel

Public
Like
1
bragreel
Home
Code
5
frontend
1
routes
6
utils
4
README.md
H
index.tsx
Branches
11
Pull requests
Remixes
1
History
Environment variables
1
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
5/21/2025
README.md

API Project

A Hono-based API with modular routes.

Project Structure

/
├── index.tsx         # Main entry point for the API
├── routes/           # Directory for API route modules
│   └── favicon.ts    # Favicon extraction endpoint
├── frontend/         # Frontend files
│   └── index.html    # HTML test form
├── utils/            # Utility functions
│   └── getDomain.tsx # Function to extract domain from URL
└── README.md         # This documentation file

API Endpoints

GET /

Serves an HTML form for testing the favicon extraction functionality.

GET /api

Returns information about the API endpoints.

Example Response:

{ "message": "Favicon Extractor API", "status": "success", "timestamp": "2025-05-20T18:16:58.497Z", "endpoints": [ { "path": "/favicon", "method": "POST", "description": "Extract favicon from URL" }, { "path": "/favicon/notion", "method": "POST", "description": "Process Notion webhook and update page icon" }, { "path": "/embed", "method": "POST", "description": "Add URL embed to a Notion page" } ] }

POST /favicon

Extracts a favicon from a provided URL.

Request Body:

{ "url": "https://example.com" }

Success Response:

{ "success": true, "faviconUrl": "https://example.com/favicon.ico", "contentType": "image/x-icon", "faviconBase64": "base64-encoded-favicon-data" }

Error Response:

{ "success": false, "message": "Could not find favicon for the provided URL" }

POST /favicon/notion

Handles Notion webhooks to extract a favicon from a URL and update the corresponding Notion page with the favicon.

Request Body (from Notion webhook):

{ "pageId": "notion-page-id", "url": "https://example.com" }

Success Response:

{ "success": true, "message": "Favicon found and Notion page updated", "pageId": "notion-page-id", "url": "https://example.com", "faviconUrl": "https://example.com/favicon.ico" }

Error Response:

{ "success": false, "error": "Failed to update Notion page", "details": { /* error details */ } }

POST /embed

Adds an embed block with the provided URL to a Notion page.

Request Body:

{ "pageId": "notion-page-id", "url": "https://example.com" }

Success Response:

{ "success": true, "message": "Embed added successfully", "pageId": "notion-page-id", "url": "https://example.com", "response": { /* Notion API response */ } }

Error Response:

{ "success": false, "message": "Failed to add embed", "error": "Error message" }

Note: This endpoint requires a NOTION_API_KEY environment variable to be set with a valid Notion API key.

Implementation Details

The API is built using Hono, a lightweight web framework. Each route is modularized in its own file for better organization and maintainability.

Favicon Extraction

The favicon endpoint attempts multiple strategies to extract a favicon:

  1. First tries the standard /favicon.ico path
  2. If that fails, it parses the HTML to find favicon link tags
  3. Returns the favicon URL and, for direct API calls, the base64-encoded favicon data

Notion Integration

The /favicon/notion endpoint integrates with the Notion API to:

  1. Receive webhooks from Notion containing a page ID and URL
  2. Extract the favicon from the provided URL
  3. Update the Notion page with the favicon URL as the page icon

This integration requires a Notion API key to be set as an environment variable (NOTION_API_KEY). You'll need to create an integration in the Notion workspace and grant it access to the relevant pages or databases.

Adding New Routes

To add a new route:

  1. Create a new file in the /routes directory
  2. Export a Hono router with your endpoint handlers
  3. Import and mount the router in index.tsx

Example:

// In /routes/newEndpoint.ts import { Hono } from "https://esm.sh/hono@3.11.7"; const router = new Hono(); router.get("/", (c) => { return c.json({ message: "New endpoint" }); }); export default router; // In index.tsx import newEndpointRouter from "./routes/newEndpoint.ts"; // Mount the new router app.route("/new-endpoint", newEndpointRouter);
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareersBrandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.