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%20%22Optional%20title%22?q=api&page=142&format=json

For typeahead suggestions, use the /typeahead endpoint:

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

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

Found 14030 results for "api"(885ms)

conceptindex.js29 matches

@joinโ€ขUpdated 5 days ago
6 appName: 'RackTracker',
7 version: '1.0.0',
8 apiEndpoint: '/api'
9};
10
18};
19
20// API functions
21const api = {
22 async getMatches() {
23 try {
24 const response = await fetch(`${initialData.apiEndpoint}/matches`);
25 if (!response.ok) throw new Error('Failed to fetch matches');
26 return await response.json();
33 async getMatch(id) {
34 try {
35 const response = await fetch(`${initialData.apiEndpoint}/matches/${id}`);
36 if (!response.ok) throw new Error('Failed to fetch match');
37 return await response.json();
44 async createMatch(matchData) {
45 try {
46 const response = await fetch(`${initialData.apiEndpoint}/matches`, {
47 method: 'POST',
48 headers: {
62 async recordRack(matchId, winnerId, events = []) {
63 try {
64 const response = await fetch(`${initialData.apiEndpoint}/matches/${matchId}/rack`, {
65 method: 'POST',
66 headers: {
80 async undoLastRack(matchId, rackId) {
81 try {
82 const response = await fetch(`${initialData.apiEndpoint}/matches/${matchId}/rack/${rackId}`, {
83 method: 'DELETE',
84 });
94 async exportMatch(matchId, format = 'json') {
95 try {
96 const response = await fetch(`${initialData.apiEndpoint}/export/match/${matchId}?format=${format}`);
97 if (!response.ok) throw new Error(`Failed to export match as ${format}`);
98
110 async getMatchSummary(matchId) {
111 try {
112 const response = await fetch(`${initialData.apiEndpoint}/export/match/${matchId}/summary`);
113 if (!response.ok) throw new Error('Failed to get match summary');
114 return await response.text();
136
137 // Load and display matches
138 api.getMatches().then(matches => {
139 state.matches = matches;
140
162 matchCard.querySelector('.tournament-name').textContent = match.tournament_id ? 'Tournament' : 'Friendly Match';
163 matchCard.querySelector('.game-type').textContent = match.game_type;
164 matchCard.querySelector('.player-a').textContent = `Player A`; // Would need player names from API
165 matchCard.querySelector('.player-b').textContent = `Player B`; // Would need player names from API
166 matchCard.querySelector('.score').textContent = `${match.player_a_score}-${match.player_b_score}`;
167 matchCard.querySelector('.race-info').textContent = `Race to ${match.race_to}`;
231 }
232
233 // Create match via API
234 const match = await api.createMatch(matchData);
235
236 if (match) {
247 async renderMatchScoring(matchId) {
248 // Fetch latest match data
249 const match = await api.getMatch(matchId);
250 if (!match) {
251 alert('Failed to load match data');
268 document.querySelector('.tournament-name').textContent = match.tournament_id ? 'Tournament' : 'Friendly Match';
269 document.querySelector('.game-info').textContent = `${match.game_type} (${match.table_size})`;
270 document.querySelector('.player-a-name').textContent = 'Player A'; // Would need player name from API
271 document.querySelector('.player-b-name').textContent = 'Player B'; // Would need player name from API
272 document.querySelector('.player-a-btn-name').textContent = 'Player A';
273 document.querySelector('.player-b-btn-name').textContent = 'Player B';
314
315 const lastRack = match.racks[match.racks.length - 1];
316 const updatedMatch = await api.undoLastRack(match.id, lastRack.id);
317
318 if (updatedMatch) {
330 const confirm = window.confirm('End match before completion? This will mark the match as completed with the current score.');
331 if (confirm) {
332 // In a real implementation, we would call an API to end the match
333 views.renderMatchComplete(match.id);
334 }
341 // Helper functions
342 async function recordRackWin(winnerId) {
343 // Convert pending events to API format
344 const events = state.pendingEvents.map(eventId => {
345 let eventType;
359 });
360
361 const updatedMatch = await api.recordRack(match.id, winnerId, events);
362
363 if (updatedMatch) {
418 async renderMatchComplete(matchId) {
419 // Fetch latest match data
420 const match = await api.getMatch(matchId);
421 if (!match) {
422 alert('Failed to load match data');
436 document.querySelector('.tournament-name').textContent = match.tournament_id ? 'Tournament' : 'Friendly Match';
437 document.querySelector('.game-info').textContent = `${match.game_type} (${match.table_size})`;
438 document.querySelector('.player-a-name').textContent = 'Player A'; // Would need player name from API
439 document.querySelector('.player-b-name').textContent = 'Player B'; // Would need player name from API
440 document.querySelector('.score').textContent = `${match.player_a_score}-${match.player_b_score}`;
441
486 // Export buttons
487 document.getElementById('export-json').addEventListener('click', async () => {
488 const data = await api.exportMatch(match.id, 'json');
489 if (data) {
490 downloadJSON(data, `match_${match.id}_export.json`);
495
496 document.getElementById('export-csv').addEventListener('click', async () => {
497 const data = await api.exportMatch(match.id, 'csv');
498 if (data) {
499 downloadText(data, `match_${match.id}_export.csv`);
504
505 document.getElementById('export-summary').addEventListener('click', async () => {
506 const data = await api.getMatchSummary(match.id);
507 if (data) {
508 showTextModal('Match Summary', data);
513
514 document.getElementById('export-fargo').addEventListener('click', async () => {
515 const data = await api.exportMatch(match.id, 'fargo');
516 if (data) {
517 downloadJSON(data, `match_${match.id}_fargo.json`);

conceptexport.ts1 match

@joinโ€ขUpdated 5 days ago
170 } else if (format === 'challonge') {
171 // Generate Challonge compatible format
172 // This is a simplified example - actual format would depend on Challonge's API
173 const challongeFormat = {
174 match: {

conceptREADME.md5 matches

@joinโ€ขUpdated 5 days ago
7## Key Principles & Design Philosophy
8
91. **Speed First**: Every interaction is optimized for rapid data entry during fast-paced tournaments.
102. **Focused Nuance**: Only capture objective, high-value data points that require minimal effort.
113. **Mobile Optimized**: Primary interface designed for smartphones and tablets used by TDs at the table.
87
88### Backend
89- **API Layer**: RESTful endpoints for data processing
90- **Authentication**: Simple user management for TDs
91- **Business Logic**: Match progression, statistics calculation
134### Potential Integrations
135- **FargoRate**: Export match results in compatible format
136 - Investigation needed for direct API integration
137 - Fallback to formatted export for manual entry
138
139- **Challonge**: Update bracket progress
140 - Explore API options for automatic updates
141 - Provide formatted data for manual entry
142
186- React for the frontend interface
187- SQLite for data storage
188- RESTful API for data access
189- Service workers for offline capability
190

firstREADME.md12 matches

@gthmbriโ€ขUpdated 5 days ago
5## Structure
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
11- `services/` - External API integrations (Twitter API)
12
13## API Endpoints
14
15- `GET /api/tweets` - Get tweets with pagination
16- `GET /api/tweets/:id` - Get a single tweet by ID
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
22## Environment Variables
23
24- `TWITTER_API_KEY` - Twitter API key
25- `TWITTER_API_SECRET` - Twitter API secret
26- `TWITTER_BEARER_TOKEN` - Twitter bearer token

firsttypes.ts1 match

@gthmbriโ€ขUpdated 5 days ago
35}
36
37export interface ApiResponse<T> {
38 success: boolean;
39 data?: T;

firstapp.js6 matches

@gthmbriโ€ขUpdated 5 days ago
36}
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();
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();
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();
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();
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();

firstindex.ts2 matches

@gthmbriโ€ขUpdated 5 days ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { initDatabase } from "./database/migrations.ts";
3import apiRouter from "./routes/api.ts";
4import staticRouter from "./routes/static.ts";
5
24
25// Mount routers
26app.route("/api", apiRouter);
27app.route("/", staticRouter);
28

firstapi.ts10 matches

@gthmbriโ€ขUpdated 5 days ago
9import { TwitterClient } from "../services/twitter.ts";
10
11// Create API router
12const api = new Hono();
13
14// Enable CORS
15api.use("/*", cors());
16
17// Get tweets with pagination
18api.get("/tweets", async (c) => {
19 const limit = parseInt(c.req.query("limit") || "50");
20 const offset = parseInt(c.req.query("offset") || "0");
30
31// Get a single tweet by ID
32api.get("/tweets/:id", async (c) => {
33 const id = c.req.param("id");
34
46
47// Get metrics history for a tweet
48api.get("/tweets/:id/metrics", async (c) => {
49 const id = c.req.param("id");
50
59
60// Get top tweets
61api.get("/top-tweets", async (c) => {
62 const limit = parseInt(c.req.query("limit") || "10");
63
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");
87
88// Search tweets
89api.get("/search", async (c) => {
90 const query = c.req.query("q");
91 if (!query) {
105});
106
107export default api;

firsttwitter.ts7 matches

@gthmbriโ€ขUpdated 5 days ago
1import { Tweet, TwitterUser, upsertTweet, upsertUser, recordMetrics } from "../database/queries.ts";
2
3// Twitter API v2 endpoints
4const TWITTER_API_BASE = "https://api.twitter.com/2";
5
6/**
7 * Twitter API client
8 */
9export class TwitterClient {
19
20 /**
21 * Make an authenticated request to the Twitter API
22 */
23 private async request(endpoint: string, params: Record<string, string> = {}): Promise<any> {
24 const url = new URL(`${TWITTER_API_BASE}${endpoint}`);
25
26 // Add query parameters
37 if (!response.ok) {
38 const errorText = await response.text();
39 throw new Error(`Twitter API error (${response.status}): ${errorText}`);
40 }
41
193 if (tweetIds.length === 0) return;
194
195 // Twitter API allows up to 100 tweets per request
196 const chunks = [];
197 for (let i = 0; i < tweetIds.length; i += 100) {

firstREADME.md7 matches

@gthmbriโ€ขUpdated 5 days ago
1# Tweet Metrics Tracker
2
3This application scrapes tweets and other metrics from Twitter/X API, stores them in a SQLite database, and displays them in a web interface.
4
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
19โ”‚ โ”‚ โ””โ”€โ”€ queries.ts # DB query functions
20โ”‚ โ”œโ”€โ”€ services/
21โ”‚ โ”‚ โ””โ”€โ”€ twitter.ts # Twitter API integration
22โ”‚ โ”œโ”€โ”€ routes/
23โ”‚ โ”‚ โ”œโ”€โ”€ api.ts # API routes
24โ”‚ โ”‚ โ””โ”€โ”€ static.ts # Static file serving
25โ”‚ โ”œโ”€โ”€ cron.ts # Cron job for data fetching
39
401. Set up the following environment variables in Val Town:
41 - `TWITTER_API_KEY` - Your Twitter/X API key
42 - `TWITTER_API_SECRET` - Your Twitter/X API secret
43 - `TWITTER_BEARER_TOKEN` - Your Twitter/X bearer token
44
49- Access the web interface to view tweets and metrics
50- The data is automatically updated via a cron job
51- Use the API endpoints to access the data programmatically

new-val-api-demo

@shouserโ€ขUpdated 1 day ago
This is an example of using the API to create a val.

groq-api2 file matches

@cameronpakโ€ขUpdated 1 day ago
snartapi
mux
Your friendly, neighborhood video API.