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=448&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 20498 results for "api"(8612ms)

ReubenCourseList.tsx3 matches

@reubenoguta_Valtown•Updated 4 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState } from "https://esm.sh/react@18.2.0";
3import type { Course, User, ApiResponse } from "../../shared/types.ts";
4
5interface CourseListProps {
23 setEnrolling(courseId);
24 try {
25 const response = await fetch(`/api/courses/${courseId}/enroll`, {
26 method: "POST"
27 });
28
29 const data: ApiResponse = await response.json();
30
31 if (data.success) {

refashionedtypes.ts1 match

@jeffy•Updated 4 weeks ago
128}
129
130export interface ApiResponse<T = any> {
131 success: boolean;
132 data?: T;

refashionedREADME.md7 matches

@jeffy•Updated 4 weeks ago
53
54## Getting Started
551. The backend serves the frontend and API endpoints
562. SQLite database is automatically initialized
573. Sample data is seeded on first run
584. Access the site at the HTTP endpoint URL
59
60## API Endpoints
61- `GET /` - Homepage
62- `GET /api/products` - Product listing with filters
63- `GET /api/products/:id` - Product details
64- `POST /api/auth/login` - User authentication
65- `POST /api/cart` - Cart operations
66- `POST /api/orders` - Order placement
67- `GET /admin/*` - Admin dashboard (protected)

ReubenDashboard.tsx3 matches

@reubenoguta_Valtown•Updated 4 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
3import type { User, Course, Exam, ApiResponse } from "../../shared/types.ts";
4import CourseList from "./CourseList.tsx";
5import CourseDetail from "./CourseDetail.tsx";
32 const loadCourses = async () => {
33 try {
34 const response = await fetch("/api/courses");
35 const data: ApiResponse<Course[]> = await response.json();
36
37 if (data.success && data.data) {

Gymtrackingtypes.ts2 matches

@lily_2025•Updated 4 weeks ago
72}
73
74// API Response types
75export interface ApiResponse<T> {
76 success: boolean;
77 data?: T;

GymtrackingREADME.md1 match

@lily_2025•Updated 4 weeks ago
41## Tech Stack
42
43- **Backend**: Hono (TypeScript API framework)
44- **Frontend**: React with TypeScript
45- **Database**: SQLite

ReubenLogin.tsx3 matches

@reubenoguta_Valtown•Updated 4 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState } from "https://esm.sh/react@18.2.0";
3import type { User, ApiResponse, LoginRequest, RegisterRequest } from "../../shared/types.ts";
4
5interface LoginProps {
25
26 try {
27 const endpoint = isLogin ? "/api/auth/login" : "/api/auth/register";
28 const payload = isLogin
29 ? { email: formData.email, password: formData.password } as LoginRequest
36 });
37
38 const data: ApiResponse<User> = await response.json();
39
40 if (data.success && data.data) {

ReubenApp.tsx4 matches

@reubenoguta_Valtown•Updated 4 weeks ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2import React, { useState, useEffect } from "https://esm.sh/react@18.2.0";
3import type { User, ApiResponse } from "../../shared/types.ts";
4import Dashboard from "./Dashboard.tsx";
5import Login from "./Login.tsx";
16 const checkAuth = async () => {
17 try {
18 const response = await fetch("/api/auth/me");
19 const data: ApiResponse<User> = await response.json();
20
21 if (data.success && data.data) {
36 const handleLogout = async () => {
37 try {
38 await fetch("/api/auth/logout", { method: "POST" });
39 setUser(null);
40 } catch (err) {

Reubenindex.ts10 matches

@reubenoguta_Valtown•Updated 4 weeks ago
17await runMigrations();
18
19// API routes
20app.route("/api/auth", auth);
21app.route("/api/courses", courses);
22app.route("/api", exams);
23app.route("/api", submissions);
24
25// Static file serving and frontend routes
27
28// Health check endpoint
29app.get("/api/health", (c) => {
30 return c.json({
31 status: "healthy",
32 timestamp: new Date().toISOString(),
33 service: "LMS API"
34 });
35});
36
37// 404 handler for API routes
38app.notFound((c) => {
39 if (c.req.path.startsWith("/api/")) {
40 return c.json({ success: false, error: "Endpoint not found" }, 404);
41 }
42 // For non-API routes, serve the main app (SPA routing)
43 return staticRoutes.fetch(new Request(new URL("/", c.req.url)));
44});

Reubensubmissions.ts28 matches

@reubenoguta_Valtown•Updated 4 weeks ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { SubmitExamRequest, ApiResponse, User, ExamSubmission, Question, GradeResult } from "../../shared/types.ts";
3import * as db from "../database/queries.ts";
4import { requireAuth, requireInstructor } from "./auth.ts";
65
66 if (isNaN(examId)) {
67 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
68 }
69
70 if (user.role !== 'student') {
71 return c.json<ApiResponse>({ success: false, error: "Only students can submit exams" }, 403);
72 }
73
75 const exam = await db.getExamById(examId);
76 if (!exam) {
77 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
78 }
79
80 if (!exam.is_published) {
81 return c.json<ApiResponse>({ success: false, error: "Exam is not published" }, 403);
82 }
83
85 const enrolled = await db.isUserEnrolled(user.id, exam.course_id);
86 if (!enrolled) {
87 return c.json<ApiResponse>({ success: false, error: "Not enrolled in this course" }, 403);
88 }
89
91 const existingSubmission = await db.getSubmission(examId, user.id);
92 if (existingSubmission) {
93 return c.json<ApiResponse>({ success: false, error: "Exam already submitted" }, 400);
94 }
95
99 const now = new Date();
100 if (now > dueDate) {
101 return c.json<ApiResponse>({ success: false, error: "Exam deadline has passed" }, 400);
102 }
103 }
137 }
138
139 return c.json<ApiResponse<{ submission: ExamSubmission; gradeResults: GradeResult[] }>>({
140 success: true,
141 data: { submission, gradeResults }
143 } catch (error) {
144 console.error("Submit exam error:", error);
145 return c.json<ApiResponse>({ success: false, error: "Failed to submit exam" }, 500);
146 }
147});
154
155 if (isNaN(examId)) {
156 return c.json<ApiResponse>({ success: false, error: "Invalid exam ID" }, 400);
157 }
158
160 const exam = await db.getExamById(examId);
161 if (!exam) {
162 return c.json<ApiResponse>({ success: false, error: "Exam not found" }, 404);
163 }
164
165 const course = await db.getCourseById(exam.course_id);
166 if (!course || course.instructor_id !== user.id) {
167 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
168 }
169
170 const submissionList = await db.getExamSubmissions(examId);
171 return c.json<ApiResponse>({ success: true, data: submissionList });
172 } catch (error) {
173 console.error("Get submissions error:", error);
174 return c.json<ApiResponse>({ success: false, error: "Failed to get submissions" }, 500);
175 }
176});
183
184 if (isNaN(submissionId)) {
185 return c.json<ApiResponse>({ success: false, error: "Invalid submission ID" }, 400);
186 }
187
197
198 if (result.rows.length === 0) {
199 return c.json<ApiResponse>({ success: false, error: "Submission not found" }, 404);
200 }
201
206 if (user.role === 'student') {
207 if (submissionData.user_id !== user.id) {
208 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
209 }
210 } else if (user.role === 'instructor') {
211 const course = await db.getCourseById(submissionData.course_id);
212 if (!course || course.instructor_id !== user.id) {
213 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
214 }
215 }
218 const questions = await db.getExamQuestions(submissionData.exam_id);
219
220 return c.json<ApiResponse>({
221 success: true,
222 data: {
227 } catch (error) {
228 console.error("Get submission error:", error);
229 return c.json<ApiResponse>({ success: false, error: "Failed to get submission" }, 500);
230 }
231});
239
240 if (isNaN(submissionId)) {
241 return c.json<ApiResponse>({ success: false, error: "Invalid submission ID" }, 400);
242 }
243
244 if (typeof score !== 'number' || score < 0) {
245 return c.json<ApiResponse>({ success: false, error: "Invalid score" }, 400);
246 }
247
256
257 if (result.rows.length === 0) {
258 return c.json<ApiResponse>({ success: false, error: "Submission not found" }, 404);
259 }
260
262 const course = await db.getCourseById(submissionData.course_id);
263 if (!course || course.instructor_id !== user.id) {
264 return c.json<ApiResponse>({ success: false, error: "Access denied" }, 403);
265 }
266
267 // Validate score doesn't exceed max
268 if (score > submissionData.max_score) {
269 return c.json<ApiResponse>({
270 success: false,
271 error: `Score cannot exceed maximum of ${submissionData.max_score}`
274
275 await db.updateSubmissionScore(submissionId, score, user.id);
276 return c.json<ApiResponse>({ success: true, data: { message: "Score updated successfully" } });
277 } catch (error) {
278 console.error("Grade submission error:", error);
279 return c.json<ApiResponse>({ success: false, error: "Failed to update score" }, 500);
280 }
281});

api-workshop

@danarddanielsjr•Updated 1 day ago

API_WORKSHOP

@justjordan15•Updated 1 day ago
replicate
Run AI with an API
fiberplane
Purveyors of Hono tooling, API Playground enthusiasts, and creators of 🪿 HONC 🪿 (https://honc.dev)