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
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let callPrivateAPI = async ({ handle, val, method = "GET", secret }) => {
let endpoint;
if (handle && val) {
endpoint = `${handle}.${val}`;
}
else {
endpoint = "galligan.simpleTest";
}
const valTownUrl = "https://api.val.town/v1/run/" + endpoint;
// Make an authenticated request to Val Town API
const response = await fetchJSON(valTownUrl, {
method,
headers: {
Authorization: "Bearer " + secret,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
});
// Check if the request was successful
if (response.status !== 200) {
throw new Error(`Request failed with status code ${response.status}`);
}
else if (endpoint === "@galligan.simpleTest") {
return "Success calling @galligan.simpleTest. To test a specific endpoint, please set `handle` and `val` as arguments";
}
// If the request was successful and endpoint is not simpleTest, return the response
return response;
};
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