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=171&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 14398 results for "api"(1759ms)

31 setError(null);
32
33 const response = await fetch(`/api/chat/rooms/${room.id}/messages`);
34 const data = await response.json();
35
60
61 try {
62 const response = await fetch(`/api/chat/rooms/${room.id}/messages`, {
63 method: 'POST',
64 headers: {
1# Backend API
2
3This directory contains the backend API for the Side Hustle Hub application.
4
5## Structure
6
7- `index.ts`: Main entry point for the API
8- `database/`: Database schema and queries
9- `routes/`: API route handlers
10
11## API Endpoints
12
13### Users
14
15- `POST /api/users`: Create a new user
16- `GET /api/users/:username`: Get a user by username
17
18### Opportunities
19
20- `GET /api/opportunities`: Get all opportunities
21- `GET /api/opportunities/category/:category`: Get opportunities by category
22- `POST /api/opportunities`: Create a new opportunity
23
24### Chat
25
26- `GET /api/chat/rooms`: Get all chat rooms
27- `GET /api/chat/rooms/:id`: Get a specific chat room
28- `GET /api/chat/rooms/:id/messages`: Get messages for a chat room
29- `POST /api/chat/rooms/:id/messages`: Post a message to a chat room
30
31### Static Files
20app.use("*", cors());
21
22// API routes
23app.route("/api/users", usersRoutes);
24app.route("/api/opportunities", opportunitiesRoutes);
25app.route("/api/chat", chatRoutes);
26
27// Static routes (must be last)
7 getUserById
8} from "../database/queries.ts";
9import { ApiResponse, ChatRoom, Message, MessageInput } from "../../shared/types.ts";
10
11const app = new Hono();
16 const rooms = await getChatRooms();
17
18 return c.json<ApiResponse<ChatRoom[]>>({
19 success: true,
20 data: rooms
22 } catch (error) {
23 console.error("Error getting chat rooms:", error);
24 return c.json<ApiResponse<null>>({
25 success: false,
26 error: "Failed to get chat rooms"
35
36 if (isNaN(id)) {
37 return c.json<ApiResponse<null>>({
38 success: false,
39 error: "Invalid room ID"
44
45 if (!room) {
46 return c.json<ApiResponse<null>>({
47 success: false,
48 error: "Chat room not found"
50 }
51
52 return c.json<ApiResponse<ChatRoom>>({
53 success: true,
54 data: room
56 } catch (error) {
57 console.error("Error getting chat room:", error);
58 return c.json<ApiResponse<null>>({
59 success: false,
60 error: "Failed to get chat room"
71
72 if (isNaN(roomId)) {
73 return c.json<ApiResponse<null>>({
74 success: false,
75 error: "Invalid room ID"
80 const room = await getChatRoomById(roomId);
81 if (!room) {
82 return c.json<ApiResponse<null>>({
83 success: false,
84 error: "Chat room not found"
88 const messages = await getMessagesByChatRoom(roomId, limit, beforeId);
89
90 return c.json<ApiResponse<Message[]>>({
91 success: true,
92 data: messages
94 } catch (error) {
95 console.error("Error getting messages:", error);
96 return c.json<ApiResponse<null>>({
97 success: false,
98 error: "Failed to get messages"
108
109 if (isNaN(roomId) || !content || !user_id) {
110 return c.json<ApiResponse<null>>({
111 success: false,
112 error: "Room ID, content, and user_id are required"
117 const room = await getChatRoomById(roomId);
118 if (!room) {
119 return c.json<ApiResponse<null>>({
120 success: false,
121 error: "Chat room not found"
126 const user = await getUserById(user_id);
127 if (!user) {
128 return c.json<ApiResponse<null>>({
129 success: false,
130 error: "User not found"
140 };
141
142 return c.json<ApiResponse<Message>>({
143 success: true,
144 data: messageWithUser
146 } catch (error) {
147 console.error("Error posting message:", error);
148 return c.json<ApiResponse<null>>({
149 success: false,
150 error: "Failed to post message"
6 getUserById
7} from "../database/queries.ts";
8import { ApiResponse, Opportunity, OpportunityInput } from "../../shared/types.ts";
9
10const app = new Hono();
18 const opportunities = await getOpportunities(limit, offset);
19
20 return c.json<ApiResponse<Opportunity[]>>({
21 success: true,
22 data: opportunities
24 } catch (error) {
25 console.error("Error getting opportunities:", error);
26 return c.json<ApiResponse<null>>({
27 success: false,
28 error: "Failed to get opportunities"
40 const opportunities = await getOpportunitiesByCategory(category, limit, offset);
41
42 return c.json<ApiResponse<Opportunity[]>>({
43 success: true,
44 data: opportunities
46 } catch (error) {
47 console.error("Error getting opportunities by category:", error);
48 return c.json<ApiResponse<null>>({
49 success: false,
50 error: "Failed to get opportunities by category"
59
60 if (!title || !description || !category || !user_id) {
61 return c.json<ApiResponse<null>>({
62 success: false,
63 error: "Title, description, category, and user_id are required"
68 const user = await getUserById(user_id);
69 if (!user) {
70 return c.json<ApiResponse<null>>({
71 success: false,
72 error: "User not found"
83 );
84
85 return c.json<ApiResponse<Opportunity>>({
86 success: true,
87 data: opportunity
89 } catch (error) {
90 console.error("Error creating opportunity:", error);
91 return c.json<ApiResponse<null>>({
92 success: false,
93 error: "Failed to create opportunity"
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { createUser, getUserByUsername } from "../database/queries.ts";
3import { ApiResponse, User } from "../../shared/types.ts";
4
5const app = new Hono();
11
12 if (!username || !display_name) {
13 return c.json<ApiResponse<null>>({
14 success: false,
15 error: "Username and display name are required"
20 const existingUser = await getUserByUsername(username);
21 if (existingUser) {
22 return c.json<ApiResponse<null>>({
23 success: false,
24 error: "Username already exists"
28 const user = await createUser(username, display_name);
29
30 return c.json<ApiResponse<User>>({
31 success: true,
32 data: user
34 } catch (error) {
35 console.error("Error creating user:", error);
36 return c.json<ApiResponse<null>>({
37 success: false,
38 error: "Failed to create user"
48
49 if (!user) {
50 return c.json<ApiResponse<null>>({
51 success: false,
52 error: "User not found"
54 }
55
56 return c.json<ApiResponse<User>>({
57 success: true,
58 data: user
60 } catch (error) {
61 console.error("Error getting user:", error);
62 return c.json<ApiResponse<null>>({
63 success: false,
64 error: "Failed to get user"
52}
53
54// API response types
55export interface ApiResponse<T> {
56 success: boolean;
57 data?: T;

untitled-8939index.ts10 matches

@pmaxx•Updated 1 week ago
41});
42
43// API Routes
44const api = new Hono();
45
46// User endpoints
47api.post("/users", async c => {
48 const { name } = await c.req.json();
49
56});
57
58api.get("/users/:id", async c => {
59 const userId = c.req.param("id");
60 const user = await getUserById(userId);
68
69// Envelope endpoints
70api.post("/users/:userId/envelopes", async c => {
71 const userId = c.req.param("userId");
72 const { name, icon, color, budget } = await c.req.json();
80});
81
82api.put("/users/:userId/envelopes/:envelopeId/allocate", async c => {
83 const userId = c.req.param("userId");
84 const envelopeId = c.req.param("envelopeId");
124
125// Transaction endpoints
126api.post("/users/:userId/transactions/import", async c => {
127 const userId = c.req.param("userId");
128 const { csvContent, mapping } = await c.req.json();
148});
149
150api.put("/users/:userId/transactions/:transactionId/assign", async c => {
151 const userId = c.req.param("userId");
152 const transactionId = c.req.param("transactionId");
164});
165
166// Mount API routes
167app.route("/api", api);
168
169// This is the entry point for HTTP vals

untitled-8939App.tsx7 matches

@pmaxx•Updated 1 week ago
7import AchievementNotification from "./AchievementNotification.tsx";
8
9const API_BASE_URL = "/api";
10
11const App: React.FC = () => {
46 try {
47 setLoading(true);
48 const response = await fetch(`${API_BASE_URL}/users/${userId}`);
49
50 if (!response.ok) {
66 try {
67 setLoading(true);
68 const response = await fetch(`${API_BASE_URL}/users`, {
69 method: "POST",
70 headers: {
92
93 try {
94 const response = await fetch(`${API_BASE_URL}/users/${user.id}/envelopes`, {
95 method: "POST",
96 headers: {
115
116 try {
117 const response = await fetch(`${API_BASE_URL}/users/${user.id}/envelopes/${envelopeId}/allocate`, {
118 method: "PUT",
119 headers: {
139 try {
140 setLoading(true);
141 const response = await fetch(`${API_BASE_URL}/users/${user.id}/transactions/import`, {
142 method: "POST",
143 headers: {
165
166 try {
167 const response = await fetch(`${API_BASE_URL}/users/${user.id}/transactions/${transactionId}/assign`, {
168 method: "PUT",
169 headers: {

untitled-8939index.html2 matches

@pmaxx•Updated 1 week ago
10
11 <!-- Fonts -->
12 <link rel="preconnect" href="https://fonts.googleapis.com">
13 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
14 <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
15
16 <!-- Error catching -->

createemailapiv22 file matches

@souravvmishra•Updated 12 hours ago

waec_api6 file matches

@seyistry•Updated 19 hours ago
snartapi
mux
Your friendly, neighborhood video API.