37</head>
38<body class={bodyStyles}>
39<h1>🪿 Welcome to my HONC API! 🪿</h1>
40<p>
41Visit <a href="/fp" class={linkStyles}>/fp</a> to view the Fiberplane API explorer.
42</p>
43</body>
HONCfiberplane.ts2 matches
1import { createFiberplane, createOpenAPISpec } from "https://esm.sh/@fiberplane/hono@0.4.4";
23export { createFiberplane, createOpenAPISpec };
37</head>
38<body class={bodyStyles}>
39<h1>🪿 Welcome to my HONC API! 🪿</h1>
40<p>
41Visit <a href="/fp" class={linkStyles}>/fp</a> to view the Fiberplane API explorer.
42</p>
43</body>
telegramBotStarterindex.ts1 match
30// This is a no-op if nothing's changed
31if (!isEndpointSet) {
32await bot.api.setWebhook(req.url, {
33secret_token: SECRET_TOKEN,
34});
queryParamsREADME.md1 match
1# Handling query params in requests
23Using the standard [URL#searchParams](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) method, you can grab query parameters out of any val that is operating using the [Web API](https://docs.val.town/api/web).
45This val demonstrates how to grab one or more query parameters. It returns the all the query parameters found as a json response.
htmlExampleREADME.md2 matches
1# Returning HTML from the Val Town Web API
23This just lets you use the standard [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with our [Web API](https://docs.val.town/api/web) to return an HTML response from this Val.
gracefulVioletTunavt3 matches
1export default async function createProject(projectName) {
2const apiToken = Deno.env.get("VAL_TOWN_RW_PROJECTS");
34const response = await fetch("https://api.val.town/v1/projects", {
5method: "POST",
6headers: {
7"Content-Type": "application/json",
8"Authorization": `Bearer ${apiToken}`,
9},
10body: JSON.stringify({
891. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
9const getForecast = async () => {
10const forecastData = await fetchJSON(
11`http://dataservice.accuweather.com/forecasts/v1/daily/1day/${accuweatherCityCode}?apikey=${process.env.accuWeather}&details=true&metric=true`,
12);
13return forecastData.DailyForecasts[0];
projectConverterDraftconverter.ts15 matches
3}
45async function convertValToProject(input: string, apiToken: string): Promise<string> {
6try {
7const projectName = generateProjectName();
89// Create a new project
10const projectResponse = await fetch("https://api.val.town/v1/projects", {
11method: "POST",
12headers: {
13"Content-Type": "application/json",
14"Authorization": `Bearer ${apiToken}`,
15},
16body: JSON.stringify({
37const directories = getUniqueDirectories(files);
38for (const dir of directories) {
39await createDirectory(project.id, dir, apiToken);
40}
4142// Create all files
43for (const file of files) {
44await createFile(project.id, file, apiToken);
45}
46138}
139140async function createDirectory(projectId: string, directoryPath: string, apiToken: string): Promise<void> {
141const encodedPath = encodeURIComponent(directoryPath);
142const response = await fetch(`https://api.val.town/v1/projects/${projectId}/files/${encodedPath}`, {
143method: "POST",
144headers: {
145"Content-Type": "application/json",
146"Authorization": `Bearer ${apiToken}`,
147},
148body: JSON.stringify({ type: "directory" }),
158projectId: string,
159file: { path: string; content: string; type: string },
160apiToken: string,
161): Promise<void> {
162const validTypes = ["script", "file", "directory", "http"];
167168const encodedPath = encodeURIComponent(file.path);
169const fileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files/${encodedPath}`, {
170method: "POST",
171headers: {
172"Content-Type": "application/json",
173"Authorization": `Bearer ${apiToken}`,
174},
175body: JSON.stringify({
443app.post("/convert", async (c) => {
444try {
445const { valCode, apiToken } = await c.req.json();
446
447if (!apiToken) {
448return c.json({ message: "Error: API token is required" }, 400);
449}
450
451const result = await convertValToProject(valCode, apiToken);
452return c.json({ message: result });
453} catch (error) {