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=195&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 17729 results for "api"(977ms)

AppApp.tsx8 matches

@Zee_paulโ€ขUpdated 1 day ago
46 setState(prev => ({ ...prev, loading: true, error: null }));
47
48 let url = '/api/products';
49 if (state.searchQuery) {
50 url = `/api/products/search/${encodeURIComponent(state.searchQuery)}`;
51 } else if (state.selectedCategory) {
52 url = `/api/products/category/${encodeURIComponent(state.selectedCategory)}`;
53 }
54
68 const loadCart = async () => {
69 try {
70 const response = await fetch(`/api/cart/${state.sessionId}`);
71 const result = await response.json();
72
81 const addToCart = async (productId: number, quantity: number = 1) => {
82 try {
83 const response = await fetch(`/api/cart/${state.sessionId}/add`, {
84 method: 'POST',
85 headers: { 'Content-Type': 'application/json' },
102 const updateCartItem = async (productId: number, quantity: number) => {
103 try {
104 const response = await fetch(`/api/cart/${state.sessionId}/update`, {
105 method: 'PUT',
106 headers: { 'Content-Type': 'application/json' },
121 const removeFromCart = async (productId: number) => {
122 try {
123 const response = await fetch(`/api/cart/${state.sessionId}/remove/${productId}`, {
124 method: 'DELETE'
125 });
139 const completeOrder = async (orderData: any) => {
140 try {
141 const response = await fetch('/api/orders', {
142 method: 'POST',
143 headers: { 'Content-Type': 'application/json' },

Appchat.ts11 matches

@Zee_paulโ€ขUpdated 1 day ago
6 getAllChatRooms
7} from "../database/queries.ts";
8import type { ApiResponse, ChatMessage, ChatRoom } from "../../shared/types.ts";
9
10const app = new Hono();
21 const messages = await getChatMessages(roomId, limit);
22
23 const response: ApiResponse<ChatMessage[]> = {
24 success: true,
25 data: messages.reverse() // Reverse to show oldest first
27 return c.json(response);
28 } catch (error) {
29 const response: ApiResponse<ChatMessage[]> = {
30 success: false,
31 error: "Failed to fetch messages"
42
43 if (!roomId || !senderName || !senderType || !message) {
44 const response: ApiResponse<ChatMessage> = {
45 success: false,
46 error: "Room ID, sender name, sender type, and message are required"
50
51 if (!['customer', 'admin'].includes(senderType)) {
52 const response: ApiResponse<ChatMessage> = {
53 success: false,
54 error: "Sender type must be 'customer' or 'admin'"
80 }
81
82 const response: ApiResponse<ChatMessage> = {
83 success: true,
84 data: newMessage
87 } catch (error) {
88 console.error("Chat message error:", error);
89 const response: ApiResponse<ChatMessage> = {
90 success: false,
91 error: "Failed to send message"
128 const room = await getChatRoom(roomId);
129
130 const response: ApiResponse<ChatRoom | null> = {
131 success: true,
132 data: room
134 return c.json(response);
135 } catch (error) {
136 const response: ApiResponse<ChatRoom> = {
137 success: false,
138 error: "Failed to fetch chat room"
147 const rooms = await getAllChatRooms();
148
149 const response: ApiResponse<ChatRoom[]> = {
150 success: true,
151 data: rooms
153 return c.json(response);
154 } catch (error) {
155 const response: ApiResponse<ChatRoom[]> = {
156 success: false,
157 error: "Failed to fetch chat rooms"

Apporders.ts12 matches

@Zee_paulโ€ขUpdated 1 day ago
8 clearCart
9} from "../database/queries.ts";
10import type { ApiResponse, Order, OrderItem, CheckoutData } from "../../shared/types.ts";
11
12const app = new Hono();
21 // Validate required fields
22 if (!customerName || !customerEmail || !customerAddress) {
23 const response: ApiResponse<Order> = {
24 success: false,
25 error: "Customer name, email, and address are required"
29
30 if (!cartItems || cartItems.length === 0) {
31 const response: ApiResponse<Order> = {
32 success: false,
33 error: "Cart is empty"
54 const order = await getOrderById(orderId);
55
56 const response: ApiResponse<Order> = {
57 success: true,
58 data: order!
61 } catch (error) {
62 console.error("Order creation error:", error);
63 const response: ApiResponse<Order> = {
64 success: false,
65 error: "Failed to create order"
74 const id = parseInt(c.req.param("id"));
75 if (isNaN(id)) {
76 const response: ApiResponse<Order> = {
77 success: false,
78 error: "Invalid order ID"
83 const order = await getOrderById(id);
84 if (!order) {
85 const response: ApiResponse<Order> = {
86 success: false,
87 error: "Order not found"
90 }
91
92 const response: ApiResponse<Order> = {
93 success: true,
94 data: order
96 return c.json(response);
97 } catch (error) {
98 const response: ApiResponse<Order> = {
99 success: false,
100 error: "Failed to fetch order"
109 const id = parseInt(c.req.param("id"));
110 if (isNaN(id)) {
111 const response: ApiResponse<OrderItem[]> = {
112 success: false,
113 error: "Invalid order ID"
118 const items = await getOrderItems(id);
119
120 const response: ApiResponse<OrderItem[]> = {
121 success: true,
122 data: items
124 return c.json(response);
125 } catch (error) {
126 const response: ApiResponse<OrderItem[]> = {
127 success: false,
128 error: "Failed to fetch order items"

Appcart.ts16 matches

@Zee_paulโ€ขUpdated 1 day ago
7 clearCart
8} from "../database/queries.ts";
9import type { ApiResponse, CartSummary, CartItem } from "../../shared/types.ts";
10
11const app = new Hono();
27 };
28
29 const response: ApiResponse<CartSummary> = {
30 success: true,
31 data: cartSummary
33 return c.json(response);
34 } catch (error) {
35 const response: ApiResponse<CartSummary> = {
36 success: false,
37 error: "Failed to fetch cart"
50
51 if (!productId || typeof productId !== "number") {
52 const response: ApiResponse<void> = {
53 success: false,
54 error: "Product ID is required"
58
59 if (quantity <= 0) {
60 const response: ApiResponse<void> = {
61 success: false,
62 error: "Quantity must be greater than 0"
67 await addToCart(sessionId, productId, quantity);
68
69 const response: ApiResponse<void> = {
70 success: true
71 };
72 return c.json(response);
73 } catch (error) {
74 const response: ApiResponse<void> = {
75 success: false,
76 error: "Failed to add item to cart"
89
90 if (!productId || typeof productId !== "number") {
91 const response: ApiResponse<void> = {
92 success: false,
93 error: "Product ID is required"
97
98 if (typeof quantity !== "number" || quantity < 0) {
99 const response: ApiResponse<void> = {
100 success: false,
101 error: "Valid quantity is required"
106 await updateCartItem(sessionId, productId, quantity);
107
108 const response: ApiResponse<void> = {
109 success: true
110 };
111 return c.json(response);
112 } catch (error) {
113 const response: ApiResponse<void> = {
114 success: false,
115 error: "Failed to update cart item"
126
127 if (isNaN(productId)) {
128 const response: ApiResponse<void> = {
129 success: false,
130 error: "Invalid product ID"
135 await removeFromCart(sessionId, productId);
136
137 const response: ApiResponse<void> = {
138 success: true
139 };
140 return c.json(response);
141 } catch (error) {
142 const response: ApiResponse<void> = {
143 success: false,
144 error: "Failed to remove item from cart"
154 await clearCart(sessionId);
155
156 const response: ApiResponse<void> = {
157 success: true
158 };
159 return c.json(response);
160 } catch (error) {
161 const response: ApiResponse<void> = {
162 success: false,
163 error: "Failed to clear cart"

Appproducts.ts12 matches

@Zee_paulโ€ขUpdated 1 day ago
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getAllProducts, getProductById, getProductsByCategory, searchProducts } from "../database/queries.ts";
3import type { ApiResponse, Product } from "../../shared/types.ts";
4
5const app = new Hono();
9 try {
10 const products = await getAllProducts();
11 const response: ApiResponse<Product[]> = {
12 success: true,
13 data: products
15 return c.json(response);
16 } catch (error) {
17 const response: ApiResponse<Product[]> = {
18 success: false,
19 error: "Failed to fetch products"
28 const id = parseInt(c.req.param("id"));
29 if (isNaN(id)) {
30 const response: ApiResponse<Product> = {
31 success: false,
32 error: "Invalid product ID"
37 const product = await getProductById(id);
38 if (!product) {
39 const response: ApiResponse<Product> = {
40 success: false,
41 error: "Product not found"
44 }
45
46 const response: ApiResponse<Product> = {
47 success: true,
48 data: product
50 return c.json(response);
51 } catch (error) {
52 const response: ApiResponse<Product> = {
53 success: false,
54 error: "Failed to fetch product"
64 const products = await getProductsByCategory(category);
65
66 const response: ApiResponse<Product[]> = {
67 success: true,
68 data: products
70 return c.json(response);
71 } catch (error) {
72 const response: ApiResponse<Product[]> = {
73 success: false,
74 error: "Failed to fetch products by category"
83 const query = c.req.param("query");
84 if (!query || query.trim().length < 2) {
85 const response: ApiResponse<Product[]> = {
86 success: false,
87 error: "Search query must be at least 2 characters"
92 const products = await searchProducts(query.trim());
93
94 const response: ApiResponse<Product[]> = {
95 success: true,
96 data: products
98 return c.json(response);
99 } catch (error) {
100 const response: ApiResponse<Product[]> = {
101 success: false,
102 error: "Failed to search products"

Apptypes.ts1 match

@Zee_paulโ€ขUpdated 1 day ago
57}
58
59export interface ApiResponse<T> {
60 success: boolean;
61 data?: T;

AppREADME.md17 matches

@Zee_paulโ€ขUpdated 1 day ago
26โ”‚ โ”‚ โ””โ”€โ”€ queries.ts # Database query functions
27โ”‚ โ”œโ”€โ”€ routes/
28โ”‚ โ”‚ โ”œโ”€โ”€ products.ts # Product API endpoints
29โ”‚ โ”‚ โ”œโ”€โ”€ cart.ts # Shopping cart endpoints
30โ”‚ โ”‚ โ”œโ”€โ”€ orders.ts # Order management
31โ”‚ โ”‚ โ”œโ”€โ”€ chat.ts # Chat API endpoints
32โ”‚ โ”‚ โ””โ”€โ”€ static.ts # Static file serving
33โ”‚ โ””โ”€โ”€ index.ts # Main Hono server
48## Tech Stack
49
50- **Backend**: Hono (TypeScript API framework)
51- **Frontend**: React with TypeScript
52- **Database**: SQLite
56## Getting Started
57
58The app will be available at the HTTP endpoint once deployed. The backend serves both the API and the frontend files.
59
60## API Endpoints
61
62### Products
63- `GET /api/products` - Get all products
64- `GET /api/products/:id` - Get product by ID
65- `GET /api/products/category/:category` - Get products by category
66
67### Cart
68- `GET /api/cart/:sessionId` - Get cart contents
69- `POST /api/cart/:sessionId/add` - Add item to cart
70- `PUT /api/cart/:sessionId/update` - Update cart item
71- `DELETE /api/cart/:sessionId/remove/:productId` - Remove item from cart
72
73### Orders
74- `POST /api/orders` - Create new order
75- `GET /api/orders/:id` - Get order details
76
77### Chat
78- `GET /api/chat/messages/:roomId` - Get chat messages
79- `POST /api/chat/messages` - Send chat message
80- `GET /api/chat/stream/:roomId` - SSE stream for real-time messages

RobbieChatBox.tsx1 match

@Robbieโ€ขUpdated 1 day ago
39 };
40
41 const response = await fetch('/api/chat', {
42 method: 'POST',
43 headers: {

RobbiePredictionForm.tsx1 match

@Robbieโ€ขUpdated 1 day ago
44 };
45
46 const response = await fetch('/api/predictions', {
47 method: 'POST',
48 headers: {

RobbieApp.tsx3 matches

@Robbieโ€ขUpdated 1 day ago
45 const loadCryptos = async () => {
46 try {
47 const response = await fetch('/api/crypto');
48 if (response.ok) {
49 const data = await response.json();
57 const loadPredictions = async () => {
58 try {
59 const response = await fetch('/api/predictions');
60 if (response.ok) {
61 const data = await response.json();
69 const loadChatMessages = async () => {
70 try {
71 const response = await fetch('/api/chat');
72 if (response.ok) {
73 const data = await response.json();

RandomQuoteAPI

@Freelzyโ€ขUpdated 1 day ago

HAPI7 file matches

@dIgitalfulusโ€ขUpdated 1 day ago
apiry
Kapil01