112});
113
114export default app.fetch;
1# Insecure SSL Cert Fetch
2
3This will be useful if you're getting a `invalid peer certificate: UnknownIssuer error`.
4
5If 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/
6
7```ts
8import { insecureFetch } from "https://esm.town/v/stevekrouse/insecureFetch";
9
10const url = "https://assignment-api.uspto.gov/patent/basicSearch?query=1234567&fields=main&rows=20";
11const data = await insecureFetch(url)
12const text = await data.text();
13console.log(text)
14```
15
16Migrated from folder: Archive/insecureFetch
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function openaiUploadFile({ key, data, purpose = "assistants" }: {
16 formData.append("purpose", purpose);
17 formData.append("file", file, "data.json");
18 let result = await fetch("https://api.openai.com/v1/files", {
19 method: "POST",
20 headers: {
7
8export default async function(interval: Interval) {
9 const page = await fetch(site).then(res => res.text());
10 const date = page.match(/Last updated: <time datetime="([^"]+)">/)?.[1].toString();
11 const lastChange = await blob.get(dateChangedKey).then(res => res?.text()).catch(() => "");
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 }
15
16 while (true) {
17 const resp = await fetch(url);
18 if (!resp.ok) {
19 throw new Error(await resp.text());
32 return { data } as T;
33 }
34 const resp = await fetch(`${API_URL}${path}`, {
35 ...options,
36 headers: {
15
16 while (true) {
17 const resp = await fetch(url);
18 if (!resp.ok) {
19 throw new Error(await resp.text());
32 return { data } as T;
33 }
34 const resp = await fetch(`https://api.val.town${path}`, {
35 ...options,
36 headers: {
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
1import { email } from "https://esm.town/v/std/email?v=9";
2// Fetches a random joke.
3async function fetchRandomJoke() {
4 const response = await fetch(
5 "https://official-joke-api.appspot.com/random_joke",
6 );
8}
9
10const randomJoke = await fetchRandomJoke();
11const setup = randomJoke.setup;
12const punchline = randomJoke.punchline;