1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
2
3const url = "https://assignment-api.uspto.gov/patent/basicSearch?query=1234567&fields=main&rows=20";
4const proxyURL = new URL("https://unsecure-fetch.val-town.workers.dev");
5proxyURL.searchParams.set("url", url);
6
7// console.debug("proxyUrl: %s", proxyURL);
8// ==> proxyUrl: https://unsecure-fetch.val-town.workers.dev/?url=https%3A%2F%2Fassignment-api.uspto.gov%2Fpatent%2FbasicSearch%3Fquery%3D1234567%26fields%3Dmain%26rows%3D20
9console.log(await fetchText(proxyURL.href));
1# Insecure SSL Cert Fetch
2
3If you need to make a fetch request to a website with a dubious or non-standard SSL certificate, you can use this proxy we made on Cloudflare workers (which doesn't verify SSL certs): https://unsecure-fetch.val-town.workers.dev/
4
5Example usage below.
9 let reason: string;
10 try {
11 const res = await fetch(URL, { redirect: "follow" });
12 if (res.status !== 200) {
13 reason = `(status code: ${res.status})`;
15 }
16 } catch (e) {
17 reason = `couldn't fetch: ${e}`;
18 ok = false;
19 }
1import { email } from "https://esm.town/v/std/email?v=9";
2
3const randomJoke = await fetchRandomJoke();
4const setup = randomJoke.setup;
5const punchline = randomJoke.punchline;
9 subject: setup,
10});
11// Fetches a random joke.
12async function fetchRandomJoke() {
13 const response = await fetch(
14 "https://official-joke-api.appspot.com/random_joke",
15 );
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
1import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { getDocs } from "https://esm.town/v/stevekrouse/getSqliteDateMeDocs";
4import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
36export async function setupDatabase() {
37 await createTable();
38 const docs = await fetchJSON(thisWebURL());
39 return docs.map(args =>
40 sqlite.execute({
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const SAMPLE_JOKE = {
6 "setup": "What do you call a group of disorganized cats?",
10}
11
12const randomJoke = fetchRandomJoke();
13const setup = randomJoke.setup;
14const punchline = randomJoke.punchline;
1# Proxied fetch - https://docs.val.town/std/fetch
18};
19
20async function fetchUser(token: string): Promise<User> {
21 const resp = await fetch("https://api.val.town/v1/me", {
22 headers: {
23 Authorization: `Bearer ${token}`,
26
27 if (resp.status !== 200) {
28 throw new Error("Could not fetch user");
29 }
30
34async function isTokenValid(token) {
35 try {
36 const [visitor, owner] = await Promise.all([fetchUser(token), fetchUser(Deno.env.get("valtown"))]);
37 return visitor.id == owner.id;
38 } catch (err) {
124export const form = new Hono();
125form.get("/", Form);
126export default form.fetch;