Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=fetch&page=660&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=fetch

Returns an array of strings in format "username" or "username/projectName"

Found 7903 results for "fetch"(999ms)

auth_middlewaremain.tsx4 matches

@stevekrouse•Updated 1 year ago
46};
47
48async function fetchUser(token: string): Promise<User> {
49 const resp = await fetch("https://api.val.town/v1/me", {
50 headers: {
51 Authorization: `Bearer ${token}`,
54
55 if (resp.status !== 200) {
56 throw new Error("Could not fetch user");
57 }
58
91 const formData = await req.formData();
92 const token = formData.get("token").toString();
93 const user = await fetchUser(token);
94 if (user.username != val.username) {
95 return new Response("Unauthorized", {

fetchPaginatedDataREADME.md3 matches

@nbbaier•Updated 1 year ago
1# Fetch Paginated Data
2
3This val exports a function that loops through paginated API responses and returns the combined data as an array. It expects pagination with `next` and there to be a `data` property in the API response. This conforms to the Val Town API, so this function is useful when fetching paginated Val Town API responses for creating custom folders in [pomdtr's vscode extension](https://github.com/pomdtr/valtown-vscode).
4
5Usage:
7```ts
8const id = <vt user id>
9await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
10 headers: { Authorization: `Bearer ${Deno.env.get("valtown")}` },
11});

moon_phasemain.tsx2 matches

@fraasi•Updated 1 year ago
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const moon_phase = async (city: string): Promise<string> => {
4 let data = await fetch(`https://wttr.in/${city}?format=j1`);
5 let jsonData = await data.json();
6 return `${city}: ${jsonData["weather"][0]["astronomy"][0]["moon_phase"]}: ${

tracingmain.tsx4 matches

@saolsen•Updated 1 year ago
53
54/**
55 * Wrapper for fetch that traces the request. It also passes a propagation header
56 * so if you are calling another val that uses traced_handler their traces will
57 * be tied together.
58 */
59export async function traced_fetch(
60 input: string | URL,
61 init?: RequestInit,
62): Promise<Response> {
63 return await get_tracer().startActiveSpan(`fetch`, async (span) => {
64 const prop_output: { b3: string } = { b3: "" };
65 propagation.inject(context.active(), prop_output);
66 try {
67 const resp: Response = await fetch(input, {
68 ...init,
69 headers: {

connect4_sitemain.tsx8 matches

@saolsen•Updated 1 year ago
1/* @jsxImportSource https://esm.sh/hono/jsx */
2import { track } from "https://esm.town/v/saolsen/plausible?v=3";
3import { init, traced_fetch, traced_handler, traced, get_tracer } from "https://esm.town/v/saolsen/tracing?v=135";
4import { trace } from "npm:@opentelemetry/api";
5init("connect4_site");
40type Player = MePlayer | AgentPlayer;
41
42type AgentFetchError = {
43 kind: "agent_fetch";
44 error_message: string;
45};
61
62type Error =
63 | AgentFetchError
64 | AgentHTTPResponseError
65 | AgentInvalidActionJsonError
517 let error_player_message;
518 switch (status.error.kind) {
519 case "agent_fetch":
520 error_player_message = (
521 <div>
1087 let action_json;
1088 try {
1089 const resp = await traced_fetch(agent_url, {
1090 method: "POST",
1091 body: JSON.stringify(turn.state),
1106 } catch (e) {
1107 const error = {
1108 kind: "agent_fetch",
1109 error_message: e.message,
1110 };
1184async function handler(request): Promise<Response> {
1185 track("saolsen.connect4-site", request);
1186 return await app.fetch(request);
1187}
1188export default traced_handler(handler);

add_to_notion_from_todoistREADME.md1 match

@nerdymomocat•Updated 1 year ago
1Use todoist for quick notes to add to notion. Uses project to decide which project to fetch to add stuff to notion. Can add to page or database based on config below. Demarkation using sections in the todoist project. Extracts date for page blocks that are added as callouts.
2
3Migrated from folder: Public/add_to_notion_from_todoist

notion_paperpile_detail_fillermain.tsx5 matches

@nerdymomocat•Updated 1 year ago
1import process from "node:process";
2import { Client } from "npm:@notionhq/client";
3import { fetch } from "npm:cross-fetch";
4
5export default async function(interval: Interval) {
50 let fields = `url,title,abstract,authors,year,externalIds`;
51
52 const j = await fetch(
53 `https://api.semanticscholar.org/graph/v1/paper/search?query=${
54 encodeURIComponent(
92
93 if (doi_to_add) {
94 // const bib = await fetch('https://api.paperpile.com/api/public/convert', {
95 // method: 'POST',
96 // headers: {
108 // }
109
110 let bib = await fetch("https://doi.org/" + doi_to_add, {
111 method: "GET",
112 headers: {
150 let sem_scholar_ppid = paper.paperId;
151 let tldr = null;
152 const tl_f = await fetch(
153 `https://api.semanticscholar.org/graph/v1/paper/${encodeURIComponent(sem_scholar_ppid)}?fields=${
154 encodeURIComponent("tldr")

git_syncmain.tsx1 match

@saolsen•Updated 1 year ago
41
42async function valtown(path: string): Promise<[number, object | null]> {
43 const req = await fetch(path, {
44 headers: {
45 Authorization: "Bearer " + Deno.env.get("valtown"),

fetsmain.tsx2 matches

@pomdtr•Updated 1 year ago
29
30export const client = createClient<typeof router>({
31 fetchFn: router.fetch,
32 endpoint: `https://${val.author}-${val.name}.web.val.run`,
33});
34
35export default router.fetch;

placemarkGlobeMonitormain.tsx2 matches

@tmcw•Updated 1 year ago
2
3export default async function(interval: Interval) {
4 const versions = await fetch("https://www.figma.com/api/plugins/1323092380415927575/versions").then(r => r.json());
5 const { install_count, like_count, view_count } = versions.meta.plugin;
6
10
11 {
12 const versions = await fetch("https://www.figma.com/api/plugins/1189962635826293304/versions").then(r => r.json());
13 const { install_count, like_count, view_count } = versions.meta.plugin;
14

fetchPaginatedData2 file matches

@nbbaier•Updated 1 week ago

FetchBasic1 file match

@fredmoon•Updated 1 week ago