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=api&page=218&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 18493 results for "api"(4653ms)

my-first-valvotes.ts14 matches

@ikeali•Updated 1 week ago
7import { requireAuth } from "./auth.ts";
8import { isPollActive } from "../../shared/utils.ts";
9import type { VoteRequest, ApiResponse, User } from "../../shared/types.ts";
10
11const votes = new Hono();
19 // Validate input
20 if (!body.poll_id || !body.option_id) {
21 return c.json<ApiResponse>({
22 success: false,
23 error: "Poll ID and option ID are required"
29
30 if (isNaN(pollId) || isNaN(optionId)) {
31 return c.json<ApiResponse>({
32 success: false,
33 error: "Invalid poll ID or option ID"
38 const poll = await getPollById(pollId, user.id);
39 if (!poll) {
40 return c.json<ApiResponse>({
41 success: false,
42 error: "Poll not found"
46 // Check if poll is active
47 if (!isPollActive(poll)) {
48 return c.json<ApiResponse>({
49 success: false,
50 error: "Poll is not currently active"
54 // Check if user has already voted
55 if (poll.user_has_voted) {
56 return c.json<ApiResponse>({
57 success: false,
58 error: "You have already voted on this poll"
63 const validOption = poll.options.find(option => option.id === optionId);
64 if (!validOption) {
65 return c.json<ApiResponse>({
66 success: false,
67 error: "Invalid option for this poll"
73
74 if (!vote) {
75 return c.json<ApiResponse>({
76 success: false,
77 error: "Failed to cast vote"
79 }
80
81 return c.json<ApiResponse>({
82 success: true,
83 data: vote
86 } catch (error) {
87 console.error("Cast vote error:", error);
88 return c.json<ApiResponse>({
89 success: false,
90 error: "Internal server error"
100
101 if (isNaN(pollId)) {
102 return c.json<ApiResponse>({
103 success: false,
104 error: "Invalid poll ID"
109 const poll = await getPollById(pollId);
110 if (!poll) {
111 return c.json<ApiResponse>({
112 success: false,
113 error: "Poll not found"
117 const vote = await getUserVote(pollId, user.id);
118
119 return c.json<ApiResponse>({
120 success: true,
121 data: vote
124 } catch (error) {
125 console.error("Get user vote error:", error);
126 return c.json<ApiResponse>({
127 success: false,
128 error: "Internal server error"

my-first-valpolls.ts33 matches

@ikeali•Updated 1 week ago
11import { requireAuth } from "./auth.ts";
12import { sanitizeInput, isPollActive } from "../../shared/utils.ts";
13import type { CreatePollRequest, ApiResponse, User } from "../../shared/types.ts";
14
15const polls = new Hono();
28 const allPolls = await getAllPolls(userId);
29
30 return c.json<ApiResponse>({
31 success: true,
32 data: allPolls
35 } catch (error) {
36 console.error("Get polls error:", error);
37 return c.json<ApiResponse>({
38 success: false,
39 error: "Internal server error"
48
49 if (isNaN(pollId)) {
50 return c.json<ApiResponse>({
51 success: false,
52 error: "Invalid poll ID"
65
66 if (!poll) {
67 return c.json<ApiResponse>({
68 success: false,
69 error: "Poll not found"
71 }
72
73 return c.json<ApiResponse>({
74 success: true,
75 data: poll
78 } catch (error) {
79 console.error("Get poll error:", error);
80 return c.json<ApiResponse>({
81 success: false,
82 error: "Internal server error"
93 // Validate input
94 if (!body.title || !body.description || !body.options || !body.start_date || !body.end_date) {
95 return c.json<ApiResponse>({
96 success: false,
97 error: "Title, description, options, start_date, and end_date are required"
100
101 if (!Array.isArray(body.options) || body.options.length < 2) {
102 return c.json<ApiResponse>({
103 success: false,
104 error: "At least 2 options are required"
107
108 if (body.options.length > 10) {
109 return c.json<ApiResponse>({
110 success: false,
111 error: "Maximum 10 options allowed"
119
120 if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
121 return c.json<ApiResponse>({
122 success: false,
123 error: "Invalid date format"
126
127 if (endDate <= startDate) {
128 return c.json<ApiResponse>({
129 success: false,
130 error: "End date must be after start date"
133
134 if (endDate <= now) {
135 return c.json<ApiResponse>({
136 success: false,
137 error: "End date must be in the future"
149
150 if (pollData.options.length < 2) {
151 return c.json<ApiResponse>({
152 success: false,
153 error: "At least 2 valid options are required after sanitization"
157 const poll = await createPoll(pollData, user.id);
158
159 return c.json<ApiResponse>({
160 success: true,
161 data: poll
164 } catch (error) {
165 console.error("Create poll error:", error);
166 return c.json<ApiResponse>({
167 success: false,
168 error: "Internal server error"
178
179 if (isNaN(pollId)) {
180 return c.json<ApiResponse>({
181 success: false,
182 error: "Invalid poll ID"
186 const existingPoll = await getPollById(pollId);
187 if (!existingPoll) {
188 return c.json<ApiResponse>({
189 success: false,
190 error: "Poll not found"
194 // Check permissions
195 if (existingPoll.creator_id !== user.id && !user.is_admin) {
196 return c.json<ApiResponse>({
197 success: false,
198 error: "Permission denied"
216 const startDate = new Date(body.start_date);
217 if (isNaN(startDate.getTime())) {
218 return c.json<ApiResponse>({
219 success: false,
220 error: "Invalid start date format"
226 const endDate = new Date(body.end_date);
227 if (isNaN(endDate.getTime())) {
228 return c.json<ApiResponse>({
229 success: false,
230 error: "Invalid end date format"
236 const updatedPoll = await updatePoll(pollId, updates);
237
238 return c.json<ApiResponse>({
239 success: true,
240 data: updatedPoll
243 } catch (error) {
244 console.error("Update poll error:", error);
245 return c.json<ApiResponse>({
246 success: false,
247 error: "Internal server error"
257
258 if (isNaN(pollId)) {
259 return c.json<ApiResponse>({
260 success: false,
261 error: "Invalid poll ID"
265 const existingPoll = await getPollById(pollId);
266 if (!existingPoll) {
267 return c.json<ApiResponse>({
268 success: false,
269 error: "Poll not found"
273 // Check permissions
274 if (existingPoll.creator_id !== user.id && !user.is_admin) {
275 return c.json<ApiResponse>({
276 success: false,
277 error: "Permission denied"
282
283 if (!deleted) {
284 return c.json<ApiResponse>({
285 success: false,
286 error: "Failed to delete poll"
288 }
289
290 return c.json<ApiResponse>({
291 success: true
292 });
294 } catch (error) {
295 console.error("Delete poll error:", error);
296 return c.json<ApiResponse>({
297 success: false,
298 error: "Internal server error"
307
308 if (isNaN(pollId)) {
309 return c.json<ApiResponse>({
310 success: false,
311 error: "Invalid poll ID"
316
317 if (!poll) {
318 return c.json<ApiResponse>({
319 success: false,
320 error: "Poll not found"
337 };
338
339 return c.json<ApiResponse>({
340 success: true,
341 data: results
344 } catch (error) {
345 console.error("Get poll results error:", error);
346 return c.json<ApiResponse>({
347 success: false,
348 error: "Internal server error"

DERICKindex.ts3 matches

@deebons•Updated 1 week ago
16await runMigrations();
17
18// API routes
19app.route("/api/jobs", jobsRouter);
20app.route("/api/chat", chatRouter);
21
22// Serve static files

DERICKChatroom.tsx2 matches

@deebons•Updated 1 week ago
33 // Setup SSE connection for real-time messages
34 useEffect(() => {
35 const eventSource = new EventSource('/api/chat/stream');
36 eventSourceRef.current = eventSource;
37
83 };
84
85 const response = await fetch('/api/chat/messages', {
86 method: 'POST',
87 headers: {

my-first-valauth.ts21 matches

@ikeali•Updated 1 week ago
11} from "../database/queries.ts";
12import { isValidEmail, isValidUsername, isValidPassword, sanitizeInput } from "../../shared/utils.ts";
13import type { LoginRequest, RegisterRequest, ApiResponse } from "../../shared/types.ts";
14
15const auth = new Hono();
28 // Validate input
29 if (!username || !email || !password) {
30 return c.json<ApiResponse>({
31 success: false,
32 error: "Username, email, and password are required"
38
39 if (!isValidUsername(cleanUsername)) {
40 return c.json<ApiResponse>({
41 success: false,
42 error: "Username must be 3-20 characters, alphanumeric and underscores only"
45
46 if (!isValidEmail(cleanEmail)) {
47 return c.json<ApiResponse>({
48 success: false,
49 error: "Invalid email format"
52
53 if (!isValidPassword(password)) {
54 return c.json<ApiResponse>({
55 success: false,
56 error: "Password must be at least 6 characters"
61 const existingUser = await getUserByUsername(cleanUsername) || await getUserByEmail(cleanEmail);
62 if (existingUser) {
63 return c.json<ApiResponse>({
64 success: false,
65 error: "Username or email already exists"
89 // Return user without password hash
90 const { password_hash, ...userResponse } = user;
91 return c.json<ApiResponse>({
92 success: true,
93 data: userResponse
96 } catch (error) {
97 console.error("Registration error:", error);
98 return c.json<ApiResponse>({
99 success: false,
100 error: "Internal server error"
110
111 if (!username || !password) {
112 return c.json<ApiResponse>({
113 success: false,
114 error: "Username and password are required"
119 const user = await getUserByUsername(sanitizeInput(username));
120 if (!user) {
121 return c.json<ApiResponse>({
122 success: false,
123 error: "Invalid username or password"
128 const isValidPassword = await bcrypt.compare(password, user.password_hash);
129 if (!isValidPassword) {
130 return c.json<ApiResponse>({
131 success: false,
132 error: "Invalid username or password"
150 // Return user without password hash
151 const { password_hash, ...userResponse } = user;
152 return c.json<ApiResponse>({
153 success: true,
154 data: userResponse
157 } catch (error) {
158 console.error("Login error:", error);
159 return c.json<ApiResponse>({
160 success: false,
161 error: "Internal server error"
176 deleteCookie(c, "session_id", { path: "/" });
177
178 return c.json<ApiResponse>({ success: true });
179
180 } catch (error) {
181 console.error("Logout error:", error);
182 return c.json<ApiResponse>({
183 success: false,
184 error: "Internal server error"
193
194 if (!sessionId) {
195 return c.json<ApiResponse>({
196 success: false,
197 error: "Not authenticated"
201 const user = await getSessionUser(sessionId);
202 if (!user) {
203 return c.json<ApiResponse>({
204 success: false,
205 error: "Invalid session"
209 // Return user without password hash
210 const { password_hash, ...userResponse } = user;
211 return c.json<ApiResponse>({
212 success: true,
213 data: userResponse
216 } catch (error) {
217 console.error("Get user error:", error);
218 return c.json<ApiResponse>({
219 success: false,
220 error: "Internal server error"
228
229 if (!sessionId) {
230 return c.json<ApiResponse>({
231 success: false,
232 error: "Authentication required"
236 const user = await getSessionUser(sessionId);
237 if (!user) {
238 return c.json<ApiResponse>({
239 success: false,
240 error: "Invalid session"

DERICKJobForm.tsx1 match

@deebons•Updated 1 week ago
33 };
34
35 const response = await fetch('/api/jobs', {
36 method: 'POST',
37 headers: {

untitled-7041index.ts2 matches

@centurygenius•Updated 1 week ago
15await createTodosTable();
16
17// API routes
18app.route("/api/todos", todosRouter);
19
20// Serve static files

untitled-1496index.ts5 matches

@ikeali•Updated 1 week ago
16await runMigrations();
17
18// API routes
19app.route('/api/auth', authRoutes);
20app.route('/api/polls', pollRoutes);
21app.route('/api/votes', voteRoutes);
22
23// Health check endpoint
24app.get('/api/health', (c) => {
25 return c.json({ status: 'ok', timestamp: new Date().toISOString() });
26});

untitled-1496CreatePoll.tsx1 match

@ikeali•Updated 1 week ago
78 };
79
80 const response = await fetch('/api/polls', {
81 method: 'POST',
82 headers: {

untitled-7041App.tsx10 matches

@centurygenius•Updated 1 week ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0?deps=react@18.2.0,react-dom@18.2.0";
3import type { Todo, CreateTodoRequest, UpdateTodoRequest, ApiResponse } from "../../shared/types.ts";
4import TodoForm from "./TodoForm.tsx";
5import TodoItem from "./TodoItem.tsx";
13 const [error, setError] = useState<string | null>(null);
14
15 // Fetch todos from API
16 const fetchTodos = async () => {
17 try {
18 setLoading(true);
19 setError(null);
20 const response = await fetch("/api/todos");
21 const result: ApiResponse<Todo[]> = await response.json();
22
23 if (result.success && result.data) {
37 try {
38 setError(null);
39 const response = await fetch("/api/todos", {
40 method: "POST",
41 headers: {
45 });
46
47 const result: ApiResponse<Todo> = await response.json();
48
49 if (result.success && result.data) {
61 try {
62 setError(null);
63 const response = await fetch(`/api/todos/${id}`, {
64 method: "PUT",
65 headers: {
69 });
70
71 const result: ApiResponse<Todo> = await response.json();
72
73 if (result.success && result.data) {
87 try {
88 setError(null);
89 const response = await fetch(`/api/todos/${id}`, {
90 method: "DELETE",
91 });
92
93 const result: ApiResponse<{ deleted: boolean }> = await response.json();
94
95 if (result.success) {

Galacta3 file matches

@defunkt•Updated 30 mins ago
Marvel Rivals GPT via tracker.gg API

github-api2 file matches

@cricks_unmixed4u•Updated 6 hours ago
apiv1
apiry