-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_webhook.ruff
More file actions
49 lines (40 loc) · 1.18 KB
/
http_webhook.ruff
File metadata and controls
49 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Webhook Receiver Example
# Demonstrates receiving webhook POSTs and processing data
# Webhook log storage
let webhooks := []
# Create server
server := http_server(8000)
# Webhook endpoint
server := server.route("POST", "/webhook", func(req) {
# Parse incoming webhook data
let data := parse_json(req.body)
# Log the webhook
let log_entry := {
"timestamp": now(),
"data": data
}
push(webhooks, log_entry)
print("Received webhook:", to_json(data))
# Return success
return json_response(200, {
"success": true,
"message": "Webhook received",
"count": len(webhooks)
})
})
# Status endpoint to see all received webhooks
server := server.route("GET", "/status", func(req) {
return json_response(200, {
"total_webhooks": len(webhooks),
"webhooks": webhooks
})
})
# Health check
server := server.route("GET", "/health", func(req) {
return json_response(200, {"status": "healthy"})
})
print("Webhook receiver running on http://localhost:8000")
print("Send POST requests to: http://localhost:8000/webhook")
print("View status at: http://localhost:8000/status")
print("")
server.listen()