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/image-url.jpg?q=fetch&page=183&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 10803 results for "fetch"(741ms)

firstREADME.md2 matches

@gthmbriโ€ขUpdated 1 week ago
6
7- `index.ts` - Main entry point for the HTTP API
8- `cron.ts` - Cron job for periodically fetching and updating tweets
9- `database/` - Database schema and queries
10- `routes/` - API routes and static file serving
17- `GET /api/tweets/:id/metrics` - Get metrics history for a tweet
18- `GET /api/top-tweets` - Get top tweets by engagement
19- `GET /api/fetch/:username` - Fetch tweets for a specific user
20- `GET /api/search?q=query` - Search tweets by keyword
21

firstapp.js23 matches

@gthmbriโ€ขUpdated 1 week ago
21 searchButton: document.getElementById('searchButton'),
22 usernameInput: document.getElementById('usernameInput'),
23 fetchButton: document.getElementById('fetchButton'),
24 latestTweetsBtn: document.getElementById('latestTweetsBtn'),
25 topTweetsBtn: document.getElementById('topTweetsBtn'),
37
38// API Functions
39async function fetchTweets(page = 0, pageSize = 10) {
40 showLoading();
41 try {
42 const response = await fetch(`/api/tweets?offset=${page * pageSize}&limit=${pageSize}`);
43 if (!response.ok) throw new Error('Failed to fetch tweets');
44 const data = await response.json();
45 hideLoading();
52}
53
54async function fetchTopTweets(limit = 10) {
55 showLoading();
56 try {
57 const response = await fetch(`/api/top-tweets?limit=${limit}`);
58 if (!response.ok) throw new Error('Failed to fetch top tweets');
59 const data = await response.json();
60 hideLoading();
70 showLoading();
71 try {
72 const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
73 if (!response.ok) throw new Error('Failed to search tweets');
74 const data = await response.json();
82}
83
84async function fetchUserTweets(username) {
85 showLoading();
86 try {
87 const response = await fetch(`/api/fetch/${encodeURIComponent(username)}`);
88 if (!response.ok) throw new Error('Failed to fetch user tweets');
89 const data = await response.json();
90 hideLoading();
97}
98
99async function fetchTweetMetrics(tweetId) {
100 showLoading();
101 try {
102 const response = await fetch(`/api/tweets/${tweetId}/metrics`);
103 if (!response.ok) throw new Error('Failed to fetch tweet metrics');
104 const data = await response.json();
105 hideLoading();
254 `;
255
256 // Fetch metrics history
257 const metrics = await fetchTweetMetrics(tweetId);
258
259 // Show modal
372 state.hasMore = true;
373
374 const tweets = await fetchTweets(state.currentPage, state.pageSize);
375 state.tweets = tweets;
376 renderTweets(tweets);
384async function loadMoreTweets() {
385 state.currentPage++;
386 const tweets = await fetchTweets(state.currentPage, state.pageSize);
387
388 if (tweets.length > 0) {
398
399async function loadTopTweets() {
400 const tweets = await fetchTopTweets(20);
401 state.tweets = tweets;
402 renderTweets(tweets);
414}
415
416async function handleFetchUser() {
417 const username = elements.usernameInput.value.trim();
418 if (!username) return;
419
420 const tweets = await fetchUserTweets(username);
421 state.tweets = tweets;
422 renderTweets(tweets);
464 if (e.key === 'Enter') handleSearch();
465});
466elements.fetchButton.addEventListener('click', handleFetchUser);
467elements.usernameInput.addEventListener('keypress', e => {
468 if (e.key === 'Enter') handleFetchUser();
469});
470elements.closeModalBtn.addEventListener('click', closeMetricsModal);

firstindex.html3 matches

@gthmbriโ€ขUpdated 1 week ago
34 </div>
35 <div class="flex-1">
36 <h2 class="text-xl font-semibold mb-2">Fetch User Tweets</h2>
37 <div class="flex">
38 <input type="text" id="usernameInput" placeholder="Enter Twitter username..."
39 class="flex-1 px-4 py-2 border border-gray-300 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500">
40 <button id="fetchButton" class="bg-blue-500 text-white px-4 py-2 rounded-r-md hover:bg-blue-600">
41 Fetch
42 </button>
43 </div>

firstindex.ts1 match

@gthmbriโ€ขUpdated 1 week ago
28
29// This is the entry point for HTTP vals
30export default app.fetch;

firstapi.ts12 matches

@gthmbriโ€ขUpdated 1 week ago
24 return c.json({ success: true, data: tweets });
25 } catch (error) {
26 console.error("Error fetching tweets:", error);
27 return c.json({ success: false, error: "Failed to fetch tweets" }, 500);
28 }
29});
40 return c.json({ success: true, data: tweet });
41 } catch (error) {
42 console.error(`Error fetching tweet ${id}:`, error);
43 return c.json({ success: false, error: "Failed to fetch tweet" }, 500);
44 }
45});
53 return c.json({ success: true, data: metrics });
54 } catch (error) {
55 console.error(`Error fetching metrics for tweet ${id}:`, error);
56 return c.json({ success: false, error: "Failed to fetch metrics" }, 500);
57 }
58});
66 return c.json({ success: true, data: tweets });
67 } catch (error) {
68 console.error("Error fetching top tweets:", error);
69 return c.json({ success: false, error: "Failed to fetch top tweets" }, 500);
70 }
71});
72
73// Fetch tweets for a specific user
74api.get("/fetch/:username", async (c) => {
75 const username = c.req.param("username");
76 const count = parseInt(c.req.query("count") || "10");
81 return c.json({ success: true, data: tweets });
82 } catch (error) {
83 console.error(`Error fetching tweets for ${username}:`, error);
84 return c.json({ success: false, error: "Failed to fetch tweets" }, 500);
85 }
86});

firstcron.ts3 matches

@gthmbriโ€ขUpdated 1 week ago
5
6/**
7 * Cron job to fetch and update tweets
8 */
9export default async function() {
16 const twitterClient = new TwitterClient();
17
18 // 1. Fetch new tweets from specified accounts
19 const accounts = ["valtown", "stevekrouse", "twitter"];
20 for (const account of accounts) {
21 console.log(`Fetching tweets for ${account}...`);
22 await twitterClient.getUserTweets(account, 20);
23 }

firsttwitter.ts2 matches

@gthmbriโ€ขUpdated 1 week ago
29 });
30
31 const response = await fetch(url.toString(), {
32 headers: {
33 Authorization: `Bearer ${this.bearerToken}`,
44
45 /**
46 * Fetch tweets from a user
47 */
48 async getUserTweets(username: string, count = 10): Promise<Tweet[]> {

firstREADME.md2 matches

@gthmbriโ€ขUpdated 1 week ago
5## Features
6
7- Fetches tweets and metrics from Twitter/X API
8- Stores data in SQLite database
9- Periodically updates data using a cron job
23โ”‚ โ”‚ โ”œโ”€โ”€ api.ts # API routes
24โ”‚ โ”‚ โ””โ”€โ”€ static.ts # Static file serving
25โ”‚ โ”œโ”€โ”€ cron.ts # Cron job for data fetching
26โ”‚ โ””โ”€โ”€ index.ts # Main entry point
27โ”œโ”€โ”€ frontend/

mcpmcp-server.ts5 matches

@dinavinterโ€ขUpdated 1 week ago
83
84 // Create project
85 const createProjectResponse = await fetch("https://api.val.town/v1/projects", {
86 method: "POST",
87 headers: {
119// Function to create a file in a project
120async function createProjectFile(projectId: string, path: string, content: string, apiKey: string) {
121 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/files`, {
122 method: "POST",
123 headers: {
141// Function to set a file as HTTP handler
142async function setFileAsHttpHandler(projectId: string, path: string, apiKey: string) {
143 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/http-handler`, {
144 method: "PUT",
145 headers: {
173
174 // Get current main.tsx content
175 const getMainFileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files/main.tsx`, {
176 headers: {
177 Authorization: `Bearer ${apiKey}`,
218// Function to update a file in a project
219async function updateProjectFile(projectId: string, path: string, content: string, apiKey: string) {
220 const response = await fetch(`https://api.val.town/v1/projects/${projectId}/files/${path}`, {
221 method: "PUT",
222 headers: {

mcpmcp.ts4 matches

@dinavinterโ€ขUpdated 1 week ago
18 ReadResourceResult,
19} from "npm:@modelcontextprotocol/sdk/types.js";
20import { toFetchResponse, toReqRes } from "npm:fetch-to-node";
21import { Hono } from "npm:hono";
22import { z } from "npm:zod";
157 });
158
159 return toFetchResponse(res);
160 } catch (e) {
161 console.error(e);
229 });
230
231 return toFetchResponse(res);
232 } catch (e) {
233 console.error(e);
246});
247
248export default app.fetch;

HN-fetch-call2 file matches

@ImGqbโ€ขUpdated 8 hours ago
fetch HackerNews by API

FRAMERFetchBasic1 file match

@bresnikโ€ขUpdated 1 day ago