1export async function slackPost(token, channel, text) {
2 const resp = await fetch(
3 `https://slack.com/api/chat.postMessage`,
4 {
1fetch the contents of the Wikipedia "On this day in history" page. defaults to JSON output, but specify `?format=text`or `?format=html` for other outputs. e.g.
2
3- https://jamiedubs-wikipediatoday.web.val.run/?format=json
3
4export const stevekrouseRSS = async () => {
5 const response = await fetch("https://stevekrouse.com/");
6 const body = await response.text();
7 const $ = cheerio.load(body);
1import { fetch } from "https://esm.town/v/std/fetch";
2import { notFound } from "https://esm.town/v/wilt/notFound";
3import { thisUrl } from "https://esm.town/v/wilt/thisUrl";
122 console.log(widget);
123 if (!widget) return;
124 const templateResp = await fetch(widget.definition.msAcTemplate);
125 const template = await templateResp.text(); // Not json!
126 const dataResp = await fetch(widget.definition.data);
127 const data = await dataResp.text();
128 await self.widgets.updateByTag('simplepwa', {template, data});
150 case "/img.jpg":
151 return new Response(
152 await fetch(tinyLogomark).then((r) => r.blob()),
153 { headers: { "Content-Type": "image/jpeg" } },
154 );
2import { Readability } from "npm:@mozilla/readability";
3
4// inspired by https://www.val.town/v/stevekrouse/fetchJSON
5interface Readable {
6 title: string;
18}
19
20export const fetchReadable = async (url: string): Promise<Readable> => {
21 const r = await fetch(url, { headers: { "content-type": "text/html" }, redirect: "follow" });
22
23 try {
36 return data;
37 } catch (err) {
38 throw new Error(`fetchReadable error: ${err.message} in ${url}`);
39 }
40};
74 }
75 case "projects": {
76 const resp = await fetchDeployAPI("/projects");
77 if (resp.status != 200) {
78 throw new Error("Failed to fetch projects");
79 }
80 const projects = await resp.json();
126 }
127 case "playground": {
128 const resp = await fetchDeployAPI(`/projects/${payload.params.project}`);
129 if (resp.status != 200) {
130 throw new Error("Failed to fetch project");
131 }
132
164 const project = payload.params.project;
165
166 const resp = await fetchDeployAPI(`/projects/${project}/deployments`);
167 if (resp.status != 200) {
168 throw new Error("Failed to fetch deployments");
169 }
170
212}
213
214function fetchDeployAPI(endpoint: string, init?: RequestInit) {
215 return fetch(`https://dash.deno.com/api${endpoint}`, {
216 ...init,
217 headers: {
17 if (query.length === 0) return [];
18
19 const response = await fetch(
20 "https://search.nixos.org/backend/latest-42-nixos-23.05/_search",
21 {
1/** @jsxImportSource https://esm.sh/preact */
2import { fetch } from "https://esm.town/v/std/fetch";
3import { render } from "npm:preact-render-to-string";
4
24 );
25 }
26 return fetch(feedUrl);
27}
35
36 // we check that we are not exposing private vals
37 const resp = await fetch(`https://api.val.town/v1/alias/${author}/${name}`, {
38 headers: {
39 authorization: `Bearer ${Deno.env.get("valtown")}`,
60});
61
62export default app.fetch;
35});
36
37export default app.fetch;
38
39// #cli