Public
Script
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
export const htmlExample = () =>
new Response("<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Post HTTP Webhooks</title>
<style>
body {
font-family: sans-serif;
}
.container {
width: 400px;
margin: 0 auto;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
}
button {
background-color: #007bff;
color: white;
padding: 10px;
border: none;
cursor: pointer;
}
</style>
<script>
const webhookUrlInput = document.getElementById("webhookUrl");
const submitButton = document.getElementById("submit");
const responseDiv = document.getElementById("response");
submitButton.addEventListener("click", async () => {
const webhookUrl = webhookUrlInput.value;
const response = await fetch(webhookUrl, {
method: "POST",
});
const contentType = response.headers.get("Content-Type");
if (contentType === "application/json") {
const responseData = await response.json();
responseDiv.innerHTML = JSON.stringify(responseData, null, 2);
} else {
responseDiv.innerHTML = response.text();
}
});
</script>
</head>
<body>
<div class="container">
<h1>Post HTTP Webhooks</h1>
<input type="text" id="webhookUrl" placeholder="Enter webhook URL">
<button id="submit">Submit</button>
<div id="response"></div>
</div>
</body>
</html>
", {
headers: {
"Content-Type": "text/html",
},
});
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023