This project contains examples of HTTP APIs and webhook handlers implemented in Val Town.
The Simple API demonstrates basic HTTP request handling. You can test it with:
https://your-val-url.val.run?name=YourNamehttps://your-val-url.val.runhttps://your-val-url.val.runhttps://your-val-url.val.run?id=123The Todo API provides a complete RESTful interface for managing todo items:
title and optional completed fields)Example JSON for creating a todo:
{ "title": "Buy groceries", "completed": false }
The webhook handler processes events from external services. To use it:
WEBHOOK_SECRET environment variable in Val Town for securityx-event-type header or event query parameterx-webhook-signature header for verificationTo handle new webhook event types, add a new case to the processWebhook function and create a corresponding handler function.
If you need to modify the database schema in the Todo API:
TABLE_NAME constant (e.g., from todos_v1 to todos_v2)initDatabase function with your new schemaYou can test your APIs using tools like:
Example cURL command:
curl -X POST https://your-val-url.val.run/todos \ -H "Content-Type: application/json" \ -d '{"title": "Test todo", "completed": false}'