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=149&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 14149 results for "api"(1033ms)

tosPostItem.tsx1 match

@JoeEdoh•Updated 6 days ago
45 try {
46 const token = localStorage.getItem("tos_token");
47 const response = await fetch(`/api/posts/${post.id}/comments`, {
48 headers: {
49 "Authorization": `Bearer ${token}`

tosFeedPage.tsx5 matches

@JoeEdoh•Updated 6 days ago
26 try {
27 const currentOffset = reset ? 0 : offset;
28 const response = await fetch(`/api/posts?limit=${limit}&offset=${currentOffset}`, {
29 headers: {
30 "Authorization": `Bearer ${token}`
74
75 try {
76 const response = await fetch("/api/posts", {
77 method: "POST",
78 headers: {
107 const handleLike = async (postId: number) => {
108 try {
109 const response = await fetch(`/api/posts/${postId}/like`, {
110 method: "POST",
111 headers: {
133 const handleComment = async (postId: number, content: string) => {
134 try {
135 const response = await fetch(`/api/posts/${postId}/comments`, {
136 method: "POST",
137 headers: {
166 const handleDelete = async (postId: number) => {
167 try {
168 const response = await fetch(`/api/posts/${postId}`, {
169 method: "DELETE",
170 headers: {

untitled-8850arena-blocks.html7 matches

@robertbrook•Updated 6 days ago
237
238 try {
239 // Log start of API request
240 console.log('🔄 Starting API request to Are.na...');
241 console.time('API Request');
242
243 // Fetch data from Are.na API
244 const response = await fetch('https://api.are.na/v2/search/blocks?sort=updated_at');
245
246 // Log response received
247 console.log(`✅ Response received with status: ${response.status}`);
248 console.timeEnd('API Request');
249
250 if (!response.ok) {
251 throw new Error(`API responded with status: ${response.status}`);
252 }
253

tosMainLayout.tsx2 matches

@JoeEdoh•Updated 6 days ago
21 if (!token) return;
22
23 const response = await fetch("/api/chat/unread", {
24 headers: {
25 "Authorization": `Bearer ${token}`
54
55 // Just hit any authenticated endpoint to update online status
56 await fetch("/api/users/online", {
57 headers: {
58 "Authorization": `Bearer ${token}`

tosAuthPage.tsx2 matches

@JoeEdoh•Updated 6 days ago
23 // Login request
24 const loginData: LoginRequest = { email, password };
25 const response = await fetch("/api/auth/login", {
26 method: "POST",
27 headers: { "Content-Type": "application/json" },
40 // Signup request
41 const signupData: SignupRequest = { email, username, password };
42 const response = await fetch("/api/auth/signup", {
43 method: "POST",
44 headers: { "Content-Type": "application/json" },

tosindex.ts5 matches

@JoeEdoh•Updated 6 days ago
65});
66
67// API routes
68app.route("/api/auth", authRouter);
69app.route("/api/users", usersRouter.use(jwtMiddleware));
70app.route("/api/posts", postsRouter.use(jwtMiddleware));
71app.route("/api/chat", chatRouter.use(jwtMiddleware));
72
73// Static routes (must be last)

toschat.ts30 matches

@JoeEdoh•Updated 6 days ago
11 getUnreadMessageCounts
12} from "../database/queries.ts";
13import { ApiResponse, ChatRoom, ChatRoomMessage, Message, User } from "../../shared/types.ts";
14
15export const chatRouter = new Hono();
20 const chatRooms = await getChatRooms();
21
22 return c.json<ApiResponse<{ chatRooms: ChatRoom[] }>>({
23 success: true,
24 data: {
28 } catch (error) {
29 console.error("Get chat rooms error:", error);
30 return c.json<ApiResponse<null>>({
31 success: false,
32 error: "Internal server error"
43
44 if (isNaN(chatRoomId)) {
45 return c.json<ApiResponse<null>>({
46 success: false,
47 error: "Invalid chat room ID"
52
53 if (!success) {
54 return c.json<ApiResponse<null>>({
55 success: false,
56 error: "Failed to join chat room"
58 }
59
60 return c.json<ApiResponse<{ success: boolean }>>({
61 success: true,
62 data: {
66 } catch (error) {
67 console.error("Join chat room error:", error);
68 return c.json<ApiResponse<null>>({
69 success: false,
70 error: "Internal server error"
81
82 if (isNaN(chatRoomId)) {
83 return c.json<ApiResponse<null>>({
84 success: false,
85 error: "Invalid chat room ID"
90
91 if (!success) {
92 return c.json<ApiResponse<null>>({
93 success: false,
94 error: "Failed to leave chat room"
96 }
97
98 return c.json<ApiResponse<{ success: boolean }>>({
99 success: true,
100 data: {
104 } catch (error) {
105 console.error("Leave chat room error:", error);
106 return c.json<ApiResponse<null>>({
107 success: false,
108 error: "Internal server error"
117
118 if (isNaN(chatRoomId)) {
119 return c.json<ApiResponse<null>>({
120 success: false,
121 error: "Invalid chat room ID"
125 const messages = await getChatRoomMessages(chatRoomId);
126
127 return c.json<ApiResponse<{ messages: ChatRoomMessage[] }>>({
128 success: true,
129 data: {
133 } catch (error) {
134 console.error("Get chat room messages error:", error);
135 return c.json<ApiResponse<null>>({
136 success: false,
137 error: "Internal server error"
146
147 if (isNaN(chatRoomId)) {
148 return c.json<ApiResponse<null>>({
149 success: false,
150 error: "Invalid chat room ID"
154 const members = await getChatRoomMembers(chatRoomId);
155
156 return c.json<ApiResponse<{ members: User[] }>>({
157 success: true,
158 data: {
162 } catch (error) {
163 console.error("Get chat room members error:", error);
164 return c.json<ApiResponse<null>>({
165 success: false,
166 error: "Internal server error"
180
181 if (isNaN(receiverId)) {
182 return c.json<ApiResponse<null>>({
183 success: false,
184 error: "Invalid user ID"
187
188 if (!content || content.trim() === "") {
189 return c.json<ApiResponse<null>>({
190 success: false,
191 error: "Content is required"
196
197 if (!message) {
198 return c.json<ApiResponse<null>>({
199 success: false,
200 error: "Failed to send message"
202 }
203
204 return c.json<ApiResponse<{ message: Message }>>({
205 success: true,
206 data: {
210 } catch (error) {
211 console.error("Send direct message error:", error);
212 return c.json<ApiResponse<null>>({
213 success: false,
214 error: "Internal server error"
225
226 if (isNaN(otherUserId)) {
227 return c.json<ApiResponse<null>>({
228 success: false,
229 error: "Invalid user ID"
236 await markMessagesAsRead(userId, otherUserId);
237
238 return c.json<ApiResponse<{ messages: Message[] }>>({
239 success: true,
240 data: {
244 } catch (error) {
245 console.error("Get direct messages error:", error);
246 return c.json<ApiResponse<null>>({
247 success: false,
248 error: "Internal server error"
259
260 if (isNaN(otherUserId)) {
261 return c.json<ApiResponse<null>>({
262 success: false,
263 error: "Invalid user ID"
267 const success = await markMessagesAsRead(userId, otherUserId);
268
269 return c.json<ApiResponse<{ success: boolean }>>({
270 success: true,
271 data: {
275 } catch (error) {
276 console.error("Mark messages as read error:", error);
277 return c.json<ApiResponse<null>>({
278 success: false,
279 error: "Internal server error"
290 const unreadCounts = await getUnreadMessageCounts(userId);
291
292 return c.json<ApiResponse<{ unreadCounts: { [senderId: string]: number } }>>({
293 success: true,
294 data: {
298 } catch (error) {
299 console.error("Get unread message counts error:", error);
300 return c.json<ApiResponse<null>>({
301 success: false,
302 error: "Internal server error"

tosposts.ts30 matches

@JoeEdoh•Updated 6 days ago
10 toggleLike
11} from "../database/queries.ts";
12import { ApiResponse, Post, Comment } from "../../shared/types.ts";
13
14export const postsRouter = new Hono();
24
25 if (!content || content.trim() === "") {
26 return c.json<ApiResponse<null>>({
27 success: false,
28 error: "Content is required"
33
34 if (!post) {
35 return c.json<ApiResponse<null>>({
36 success: false,
37 error: "Failed to create post"
39 }
40
41 return c.json<ApiResponse<{ post: Post }>>({
42 success: true,
43 data: {
47 } catch (error) {
48 console.error("Create post error:", error);
49 return c.json<ApiResponse<null>>({
50 success: false,
51 error: "Internal server error"
65 const posts = await getPosts(userId, limit, offset);
66
67 return c.json<ApiResponse<{ posts: Post[] }>>({
68 success: true,
69 data: {
73 } catch (error) {
74 console.error("Get posts error:", error);
75 return c.json<ApiResponse<null>>({
76 success: false,
77 error: "Internal server error"
88
89 if (isNaN(postId)) {
90 return c.json<ApiResponse<null>>({
91 success: false,
92 error: "Invalid post ID"
97
98 if (!post) {
99 return c.json<ApiResponse<null>>({
100 success: false,
101 error: "Post not found"
103 }
104
105 return c.json<ApiResponse<{ post: Post }>>({
106 success: true,
107 data: {
111 } catch (error) {
112 console.error("Get post error:", error);
113 return c.json<ApiResponse<null>>({
114 success: false,
115 error: "Internal server error"
127
128 if (isNaN(postId)) {
129 return c.json<ApiResponse<null>>({
130 success: false,
131 error: "Invalid post ID"
136
137 if (!success) {
138 return c.json<ApiResponse<null>>({
139 success: false,
140 error: "Failed to delete post or unauthorized"
142 }
143
144 return c.json<ApiResponse<{ success: boolean }>>({
145 success: true,
146 data: {
150 } catch (error) {
151 console.error("Delete post error:", error);
152 return c.json<ApiResponse<null>>({
153 success: false,
154 error: "Internal server error"
168
169 if (isNaN(postId)) {
170 return c.json<ApiResponse<null>>({
171 success: false,
172 error: "Invalid post ID"
175
176 if (!content || content.trim() === "") {
177 return c.json<ApiResponse<null>>({
178 success: false,
179 error: "Content is required"
184
185 if (!comment) {
186 return c.json<ApiResponse<null>>({
187 success: false,
188 error: "Failed to create comment"
190 }
191
192 return c.json<ApiResponse<{ comment: Comment }>>({
193 success: true,
194 data: {
198 } catch (error) {
199 console.error("Create comment error:", error);
200 return c.json<ApiResponse<null>>({
201 success: false,
202 error: "Internal server error"
211
212 if (isNaN(postId)) {
213 return c.json<ApiResponse<null>>({
214 success: false,
215 error: "Invalid post ID"
219 const comments = await getPostComments(postId);
220
221 return c.json<ApiResponse<{ comments: Comment[] }>>({
222 success: true,
223 data: {
227 } catch (error) {
228 console.error("Get comments error:", error);
229 return c.json<ApiResponse<null>>({
230 success: false,
231 error: "Internal server error"
243
244 if (isNaN(commentId)) {
245 return c.json<ApiResponse<null>>({
246 success: false,
247 error: "Invalid comment ID"
252
253 if (!success) {
254 return c.json<ApiResponse<null>>({
255 success: false,
256 error: "Failed to delete comment or unauthorized"
258 }
259
260 return c.json<ApiResponse<{ success: boolean }>>({
261 success: true,
262 data: {
266 } catch (error) {
267 console.error("Delete comment error:", error);
268 return c.json<ApiResponse<null>>({
269 success: false,
270 error: "Internal server error"
281
282 if (isNaN(postId)) {
283 return c.json<ApiResponse<null>>({
284 success: false,
285 error: "Invalid post ID"
289 const result = await toggleLike(postId, userId);
290
291 return c.json<ApiResponse<{ liked: boolean; count: number }>>({
292 success: true,
293 data: result
295 } catch (error) {
296 console.error("Toggle like error:", error);
297 return c.json<ApiResponse<null>>({
298 success: false,
299 error: "Internal server error"

tosusers.ts17 matches

@JoeEdoh•Updated 6 days ago
7 getOnlineUsers
8} from "../database/queries.ts";
9import { ApiResponse, User, Post } from "../../shared/types.ts";
10
11export const usersRouter = new Hono();
17
18 if (isNaN(userId)) {
19 return c.json<ApiResponse<null>>({
20 success: false,
21 error: "Invalid user ID"
26
27 if (!user) {
28 return c.json<ApiResponse<null>>({
29 success: false,
30 error: "User not found"
32 }
33
34 return c.json<ApiResponse<{ user: User }>>({
35 success: true,
36 data: {
40 } catch (error) {
41 console.error("Get user error:", error);
42 return c.json<ApiResponse<null>>({
43 success: false,
44 error: "Internal server error"
63
64 if (!updatedUser) {
65 return c.json<ApiResponse<null>>({
66 success: false,
67 error: "Failed to update profile"
69 }
70
71 return c.json<ApiResponse<{ user: User }>>({
72 success: true,
73 data: {
77 } catch (error) {
78 console.error("Update profile error:", error);
79 return c.json<ApiResponse<null>>({
80 success: false,
81 error: "Internal server error"
92
93 if (isNaN(userId)) {
94 return c.json<ApiResponse<null>>({
95 success: false,
96 error: "Invalid user ID"
100 const posts = await getUserPosts(userId, currentUserId);
101
102 return c.json<ApiResponse<{ posts: Post[] }>>({
103 success: true,
104 data: {
108 } catch (error) {
109 console.error("Get user posts error:", error);
110 return c.json<ApiResponse<null>>({
111 success: false,
112 error: "Internal server error"
122
123 if (isNaN(userId)) {
124 return c.json<ApiResponse<null>>({
125 success: false,
126 error: "Invalid user ID"
130 // Only allow users to see their own liked posts
131 if (payload.id !== userId) {
132 return c.json<ApiResponse<null>>({
133 success: false,
134 error: "Unauthorized"
138 const posts = await getUserLikedPosts(userId);
139
140 return c.json<ApiResponse<{ posts: Post[] }>>({
141 success: true,
142 data: {
146 } catch (error) {
147 console.error("Get user liked posts error:", error);
148 return c.json<ApiResponse<null>>({
149 success: false,
150 error: "Internal server error"
158 const onlineUsers = await getOnlineUsers();
159
160 return c.json<ApiResponse<{ users: User[] }>>({
161 success: true,
162 data: {
166 } catch (error) {
167 console.error("Get online users error:", error);
168 return c.json<ApiResponse<null>>({
169 success: false,
170 error: "Internal server error"

tosauth.ts12 matches

@JoeEdoh•Updated 6 days ago
2import { jwt } from "https://esm.sh/hono@3.11.7/middleware/jwt";
3import { createUser, getUserByEmail, verifyUser } from "../database/queries.ts";
4import { SignupRequest, LoginRequest, ApiResponse, AuthResponse } from "../../shared/types.ts";
5
6const JWT_SECRET = Deno.env.get("JWT_SECRET") || "tos-secret-key-change-in-production";
16 // Validate input
17 if (!email || !username || !password) {
18 return c.json<ApiResponse<null>>({
19 success: false,
20 error: "Email, username, and password are required"
25 const existingUser = await getUserByEmail(email);
26 if (existingUser) {
27 return c.json<ApiResponse<null>>({
28 success: false,
29 error: "Email already in use"
34 const user = await createUser(email, username, password);
35 if (!user) {
36 return c.json<ApiResponse<null>>({
37 success: false,
38 error: "Failed to create user"
48 });
49
50 return c.json<ApiResponse<AuthResponse>>({
51 success: true,
52 data: {
57 } catch (error) {
58 console.error("Signup error:", error);
59 return c.json<ApiResponse<null>>({
60 success: false,
61 error: "Internal server error"
72 // Validate input
73 if (!email || !password) {
74 return c.json<ApiResponse<null>>({
75 success: false,
76 error: "Email and password are required"
81 const user = await verifyUser(email, password);
82 if (!user) {
83 return c.json<ApiResponse<null>>({
84 success: false,
85 error: "Invalid email or password"
95 });
96
97 return c.json<ApiResponse<AuthResponse>>({
98 success: true,
99 data: {
104 } catch (error) {
105 console.error("Login error:", error);
106 return c.json<ApiResponse<null>>({
107 success: false,
108 error: "Internal server error"
116 const payload = c.get("jwtPayload");
117
118 return c.json<ApiResponse<{ user: any }>>({
119 success: true,
120 data: {
124 } catch (error) {
125 console.error("Get current user error:", error);
126 return c.json<ApiResponse<null>>({
127 success: false,
128 error: "Internal server error"

book-lookup5 file matches

@nucky•Updated 21 hours ago
use google book api to look up bibliographic metadata elements

new-val-api-demo

@shouser•Updated 2 days ago
This is an example of using the API to create a val.
snartapi
mux
Your friendly, neighborhood video API.