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/$2?q=api&page=15&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 15629 results for "api"(3309ms)

fetch-socialsfetchMastodon.tsx2 matches

@welsonUpdated 21 hours ago
23
24 // Step 1: Look up the account ID
25 const accountLookupUrl = `https://${MASTODON_INSTANCE}/api/v1/accounts/lookup?acct=${MASTODON_USERNAME}`;
26 console.log("Looking up account ID...");
27
37 // Step 2: Fetch recent posts (statuses)
38 const statusesUrl =
39 `https://${MASTODON_INSTANCE}/api/v1/accounts/${accountId}/statuses?limit=40&exclude_replies=true&exclude_reblogs=true`;
40 console.log("Fetching recent posts...");
41

flyFlyApiClient.ts13 matches

@chadparkerUpdated 22 hours ago
1// Fly.io API client and HTTP endpoints
2import { Hono } from "https://esm.sh/hono@3.11.7";
3
9});
10
11// Types for Fly.io API responses
12interface FlyApp {
13 id: string;
47}
48
49// Base API client functions that can be imported by other files
50export class FlyApiClient {
51 private token: string;
52 private baseUrl = 'https://api.machines.dev/v1';
53
54 constructor() {
69
70 if (!response.ok) {
71 throw new Error(`Fly.io API error: ${response.status} ${response.statusText}`);
72 }
73
104app.get('/apps', async (c) => {
105 try {
106 const client = new FlyApiClient();
107 const orgSlug = c.req.query('org_slug') || 'personal';
108 const apps = await client.getApps(orgSlug);
115app.get('/apps/:appName', async (c) => {
116 try {
117 const client = new FlyApiClient();
118 const appName = c.req.param('appName');
119 const app = await client.getApp(appName);
126app.get('/apps/:appName/machines', async (c) => {
127 try {
128 const client = new FlyApiClient();
129 const appName = c.req.param('appName');
130 const machines = await client.getMachines(appName);
137app.get('/apps/:appName/machines/:machineId', async (c) => {
138 try {
139 const client = new FlyApiClient();
140 const appName = c.req.param('appName');
141 const machineId = c.req.param('machineId');
149app.get('/apps/:appName/machines/:machineId/events', async (c) => {
150 try {
151 const client = new FlyApiClient();
152 const appName = c.req.param('appName');
153 const machineId = c.req.param('machineId');
159});
160
161// Root endpoint with API documentation
162app.get('/', (c) => {
163 return c.json({
164 message: 'Fly.io API Proxy',
165 endpoints: {
166 'GET /apps': 'List all apps (optional ?org_slug=personal)',

flyindex.tsx2 matches

@chadparkerUpdated 22 hours ago
1import { FlyApiClient } from "./FlyApiClient.ts";
2
3export default async function(req: Request): Promise<Response> {
4 try {
5 const client = new FlyApiClient();
6 const response = await client.getApps();
7 const apps = response.apps || [];

ChatApp.tsx8 matches

@c15rUpdated 23 hours ago
19
20export interface AppConfig {
21 anthropicApiKey: string;
22 mcpServers: MCPServer[];
23 selectedModel: string;
36export default function App() {
37 const [config, setConfig] = useState<AppConfig>({
38 anthropicApiKey: "",
39 mcpServers: DEFAULT_MCP_SERVERS,
40 selectedModel: "claude-3-5-sonnet-20241022",
45 // Load config from localStorage on mount
46 useEffect(() => {
47 const savedApiKey = localStorage.getItem("anthropic_api_key");
48 const savedMcpServers = localStorage.getItem("mcp_servers");
49 const savedMessages = localStorage.getItem("chat_messages");
51
52 setConfig({
53 anthropicApiKey: savedApiKey || "",
54 mcpServers: savedMcpServers ? JSON.parse(savedMcpServers) : DEFAULT_MCP_SERVERS,
55 selectedModel: savedModel || "claude-3-5-sonnet-20241022",
66 }
67
68 // Show settings if no API key is configured
69 if (!savedApiKey) {
70 setShowSettings(true);
71 }
74 // Save config to localStorage when it changes
75 useEffect(() => {
76 if (config.anthropicApiKey) {
77 localStorage.setItem("anthropic_api_key", config.anthropicApiKey);
78 }
79 localStorage.setItem("mcp_servers", JSON.stringify(config.mcpServers));

ChatREADME.md10 matches

@c15rUpdated 23 hours ago
1# Anthropic Streaming Chat with MCP
2
3A mobile-optimized single page chat application that uses the Anthropic Messages API with **real-time streaming** and MCP (Model Context Protocol) server support.
4
5Source: https://www.val.town/x/c15r/Chat
16- **⏹️ Stream control** - Stop streaming at any time with the stop button
17- Full-screen mobile-optimized chat interface
18- Direct client-side Anthropic API integration with server-side streaming proxy
19- **Model selection** - Choose between different Claude models (3.5 Sonnet, 3.5 Haiku, 3 Opus, etc.) without clearing chat history
20- Configurable MCP servers with localStorage persistence
59
60The app stores configuration and chat history in localStorage:
61- `anthropic_api_key`: Your Anthropic API key
62- `selected_model`: The chosen Claude model (defaults to claude-3-5-sonnet-20241022)
63- `mcp_servers`: Array of configured MCP servers
64- `chat_messages`: Complete chat history (persists between page loads)
65
66## API Endpoints
67
68- `POST /api/chat/stream` - Real-time streaming chat responses (SSE)
69- `POST /api/chat` - Non-streaming chat responses (fallback)
70- `POST /api/test-mcp` - Test MCP server connectivity and protocol compliance
71
72## Usage
73
741. Open the app at the provided URL
752. Click "Settings" in the footer to configure your Anthropic API key and select your preferred Claude model
763. Add/remove/toggle MCP servers as needed
774. Use the "Test" button next to each MCP server to verify connectivity (shows ✅ for success, ❌ for errors)
100- **Auto-scroll**: Messages automatically scroll to bottom during streaming
101- **Auto-resize**: Input field grows with content
102- **Error Handling**: Clear error messages for API issues with stream recovery
103- **Loading States**: Visual feedback during API calls and streaming
104- **Structured Responses**: MCP tool use and results are displayed in organized, collapsible sections
105- **Clean Interface**: Maximized chat area with no header, footer contains all controls

Test2index.ts17 matches

@lee_royUpdated 1 day ago
55});
56
57// API Routes with middleware
58app.route('/api/auth', authRoutes);
59
60// Protected product routes (some require auth, some don't)
61app.use('/api/products/*', optionalAuthMiddleware); // Optional auth for viewing
62app.route('/api/products', productRoutes);
63
64// TODO: Add other route modules
65// app.use('/api/orders/*', authMiddleware);
66// app.use('/api/orders/*', customerMiddleware);
67// app.route('/api/orders', orderRoutes);
68
69// app.use('/api/solutions/*', optionalAuthMiddleware);
70// app.route('/api/solutions', solutionRoutes);
71
72// app.use('/api/admin/*', authMiddleware);
73// app.use('/api/admin/*', adminMiddleware);
74// app.route('/api/admin', adminRoutes);
75
76// Serve static files from frontend and shared directories
89 user: null, // Will be populated by frontend auth check
90 config: {
91 apiUrl: '/api',
92 stripePublishableKey: Deno.env.get('STRIPE_PUBLISHABLE_KEY') || '',
93 companyName: 'IoT Solutions Company',
127app.get("*", async c => {
128 try {
129 // For SPA routing, serve the main index.html for all non-API routes
130 const path = c.req.path;
131
132 // Skip API routes and static files
133 if (path.startsWith('/api/') ||
134 path.startsWith('/frontend/') ||
135 path.startsWith('/shared/') ||
146 user: null,
147 config: {
148 apiUrl: '/api',
149 stripePublishableKey: Deno.env.get('STRIPE_PUBLISHABLE_KEY') || '',
150 companyName: 'IoT Solutions Company',

Test2products.ts12 matches

@lee_royUpdated 1 day ago
9
10/**
11 * GET /api/products
12 * Search and filter products with pagination
13 */
43
44/**
45 * GET /api/products/featured
46 * Get featured products
47 */
66
67/**
68 * GET /api/products/categories
69 * Get all product categories
70 */
84
85/**
86 * GET /api/products/:id
87 * Get product details by ID
88 */
110
111/**
112 * GET /api/products/sku/:sku
113 * Get product details by SKU
114 */
136
137/**
138 * POST /api/products
139 * Create a new product (admin only)
140 */
174
175/**
176 * PUT /api/products/:id
177 * Update a product (admin only)
178 */
230
231/**
232 * PATCH /api/products/:id/stock
233 * Update product stock quantity (admin only)
234 */
294
295/**
296 * DELETE /api/products/:id
297 * Soft delete a product (admin only)
298 */
332
333/**
334 * GET /api/products/:id/related
335 * Get related products (same category)
336 */
369
370/**
371 * GET /api/products/category/:slug
372 * Get products by category slug
373 */
408
409/**
410 * POST /api/products/bulk-update
411 * Bulk update products (admin only)
412 */

Test2auth.ts8 matches

@lee_royUpdated 1 day ago
11
12/**
13 * POST /api/auth/register
14 * Register a new user account
15 */
77
78/**
79 * POST /api/auth/login
80 * Authenticate user and return JWT token
81 */
128
129/**
130 * POST /api/auth/refresh
131 * Refresh JWT token using refresh token
132 */
170
171/**
172 * POST /api/auth/forgot-password
173 * Send password reset email
174 */
216
217/**
218 * POST /api/auth/reset-password
219 * Reset password using reset token
220 */
272
273/**
274 * POST /api/auth/change-password
275 * Change password for authenticated user
276 */
328
329/**
330 * GET /api/auth/me
331 * Get current user profile
332 */
359
360/**
361 * PUT /api/auth/profile
362 * Update user profile
363 */

Test2stripe.ts25 matches

@lee_royUpdated 1 day ago
3import type { PaymentIntent, CheckoutRequest } from '../../shared/types.ts';
4
5// Stripe API wrapper (simplified for Val Town)
6export class StripeService {
7 private apiKey: string;
8 private baseUrl = 'https://api.stripe.com/v1';
9
10 constructor() {
11 this.apiKey = Deno.env.get('STRIPE_SECRET_KEY') || '';
12 if (!this.apiKey) {
13 console.warn('STRIPE_SECRET_KEY not found in environment variables');
14 }
19 */
20 async createPaymentIntent(amount: number, currency = 'usd', metadata?: Record<string, string>): Promise<PaymentIntent> {
21 if (!this.apiKey) {
22 throw new Error('Stripe API key not configured');
23 }
24
38 method: 'POST',
39 headers: {
40 'Authorization': `Bearer ${this.apiKey}`,
41 'Content-Type': 'application/x-www-form-urlencoded',
42 },
46 if (!response.ok) {
47 const error = await response.json();
48 throw new Error(`Stripe API error: ${error.error?.message || 'Unknown error'}`);
49 }
50
62 */
63 async retrievePaymentIntent(paymentIntentId: string): Promise<any> {
64 if (!this.apiKey) {
65 throw new Error('Stripe API key not configured');
66 }
67
68 const response = await fetch(`${this.baseUrl}/payment_intents/${paymentIntentId}`, {
69 headers: {
70 'Authorization': `Bearer ${this.apiKey}`,
71 },
72 });
74 if (!response.ok) {
75 const error = await response.json();
76 throw new Error(`Stripe API error: ${error.error?.message || 'Unknown error'}`);
77 }
78
84 */
85 async confirmPaymentIntent(paymentIntentId: string, paymentMethodId: string): Promise<any> {
86 if (!this.apiKey) {
87 throw new Error('Stripe API key not configured');
88 }
89
95 method: 'POST',
96 headers: {
97 'Authorization': `Bearer ${this.apiKey}`,
98 'Content-Type': 'application/x-www-form-urlencoded',
99 },
103 if (!response.ok) {
104 const error = await response.json();
105 throw new Error(`Stripe API error: ${error.error?.message || 'Unknown error'}`);
106 }
107
113 */
114 async createCustomer(email: string, name?: string, metadata?: Record<string, string>): Promise<any> {
115 if (!this.apiKey) {
116 throw new Error('Stripe API key not configured');
117 }
118
134 method: 'POST',
135 headers: {
136 'Authorization': `Bearer ${this.apiKey}`,
137 'Content-Type': 'application/x-www-form-urlencoded',
138 },
142 if (!response.ok) {
143 const error = await response.json();
144 throw new Error(`Stripe API error: ${error.error?.message || 'Unknown error'}`);
145 }
146
152 */
153 async createRefund(paymentIntentId: string, amount?: number, reason?: string): Promise<any> {
154 if (!this.apiKey) {
155 throw new Error('Stripe API key not configured');
156 }
157
171 method: 'POST',
172 headers: {
173 'Authorization': `Bearer ${this.apiKey}`,
174 'Content-Type': 'application/x-www-form-urlencoded',
175 },
179 if (!response.ok) {
180 const error = await response.json();
181 throw new Error(`Stripe API error: ${error.error?.message || 'Unknown error'}`);
182 }
183

Test2types.ts2 matches

@lee_royUpdated 1 day ago
190}
191
192// API Response types
193export interface ApiResponse<T = any> {
194 success: boolean;
195 data?: T;

googleGeminiAPI2 file matches

@michaelwschultzUpdated 5 hours ago

HN-fetch-call2 file matches

@ImGqbUpdated 3 days ago
fetch HackerNews by API
Kapil01
apiv1