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%22Image%20title%22?q=api&page=928&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 18393 results for "api"(3741ms)

telegramBotStarterindex.ts1 match

@WaryaaUpdated 1 month ago
30 // This is a no-op if nothing's changed
31 if (!isEndpointSet) {
32 await bot.api.setWebhook(req.url, {
33 secret_token: SECRET_TOKEN,
34 });

x_posts_collect_mainmain.tsx59 matches

@tsuchi_yaUpdated 1 month ago
10 const [query, setQuery] = React.useState("");
11 const [targetAccount, setTargetAccount] = React.useState("");
12 const [apiKey, setApiKey] = React.useState("");
13 const [searchType, setSearchType] = React.useState("Latest");
14 const [sinceDate, setSinceDate] = React.useState("");
39 const checkAuth = async () => {
40 try {
41 const response = await fetch("/api/me");
42 if (response.ok) {
43 const userData = await response.json();
97 setAuthError(null);
98 try {
99 const response = await fetch("/api/login", {
100 method: "POST",
101 headers: { "Content-Type": "application/json" },
120 setAuthError(null);
121 try {
122 const response = await fetch("/api/register", {
123 method: "POST",
124 headers: { "Content-Type": "application/json" },
138 const handleLogout = async () => {
139 try {
140 await fetch("/api/logout");
141 setUser(null);
142 // Clear sensitive data on logout
143 setApiKey("");
144 setTweets([]);
145 setError(null);
154 // No need to check for user here, useEffect handles it
155 try {
156 const response = await fetch("/api/searches");
157 if (response.ok) {
158 const searches = await response.json();
186 if (!searchName) return;
187
188 const response = await fetch("/api/searches/save", {
189 method: "POST",
190 headers: { "Content-Type": "application/json" },
214 if (!confirm("Are you sure you want to delete this saved search?")) return;
215 try {
216 const response = await fetch(`/api/searches/${searchId}/delete`, {
217 method: "POST", // Using POST due to potential Val Town limitations
218 });
242 search.until_date,
243 );
244 // Ensure API key is present before running saved search
245 if (!apiKey.trim()) {
246 setError(
247 "Please enter your SocialData API Key before running a saved search.",
248 );
249 return;
261 return;
262 }
263 if (!apiKey.trim()) {
264 setError("Please enter your SocialData API Key.");
265 return;
266 }
289 params.append("cursor", currentCursor);
290 }
291 // *** Pass API key in header ***
292 const response = await fetch(`/api/search?${params.toString()}`, {
293 headers: { "X-Api-Key": apiKey }, // Pass API key here
294 });
295
306 const errorData = await response
307 .json()
308 .catch(() => ({ message: `API Error: ${response.statusText}` }));
309 throw new Error(
310 errorData.message
311 || `API Error: ${response.statusText} on page ${pageNum}`,
312 );
313 }
318 if (data.status === "error") {
319 throw new Error(
320 data.message || `API returned an error on page ${pageNum}`,
321 );
322 }
353 }
354 },
355 [apiKey, user], // Add user dependency
356 );
357
367 return;
368 }
369 if (!apiKey.trim()) {
370 setError("Please enter your SocialData API Key.");
371 return;
372 }
562 rel: "noopener noreferrer",
563 },
564 "SocialData API",
565 ),
566 " | ",
616 ),
617 ),
618 // --- API Key Input ---
619 React.createElement(
620 "div",
625 React.createElement(
626 "label",
627 { htmlFor: "apiKey", className: "label" },
628 "API Key",
629 ),
630 React.createElement("input", {
631 type: "password",
632 id: "apiKey",
633 value: apiKey,
634 onChange: (e) => setApiKey(e.target.value),
635 placeholder: "Enter SocialData API Key",
636 className: "input",
637 }),
1088 rel: "noopener noreferrer",
1089 },
1090 "SocialData API",
1091 ),
1092 " | ",
1194 }
1195
1196 // --- API Endpoints ---
1197
1198 // Register Endpoint
1199 if (url.pathname === "/api/register" && request.method === "POST") {
1200 try {
1201 const { username, email, password } = await request.json();
1247
1248 // Login Endpoint
1249 if (url.pathname === "/api/login" && request.method === "POST") {
1250 try {
1251 const { email, password } = await request.json();
1290
1291 // Get Current User Endpoint
1292 if (url.pathname === "/api/me" && request.method === "GET") {
1293 try {
1294 const user = await getUserFromRequest(request);
1325
1326 // Logout Endpoint
1327 if (url.pathname === "/api/logout" && request.method === "GET") {
1328 // Changed to GET for simplicity, POST is often preferred
1329 return Response.json(
1341
1342 // Save Search Endpoint
1343 if (url.pathname === "/api/searches/save" && request.method === "POST") {
1344 if (!user)
1345 return Response.json({ error: "Not authenticated" }, { status: 401 });
1395
1396 // Get Saved Searches Endpoint
1397 if (url.pathname === "/api/searches" && request.method === "GET") {
1398 if (!user)
1399 return Response.json({ error: "Not authenticated" }, { status: 401 });
1415 // Delete Saved Search Endpoint
1416 if (
1417 url.pathname.startsWith("/api/searches/")
1418 && url.pathname.endsWith("/delete")
1419 && (request.method === "POST" || request.method === "DELETE")
1447 }
1448
1449 // Search API Proxy Endpoint
1450 if (url.pathname === "/api/search" && request.method === "GET") {
1451 // *** LOGIN CHECK ADDED for the proxy endpoint ***
1452 if (!user) {
1457 }
1458
1459 const apiKey = request.headers.get("X-Api-Key"); // Get API key from header sent by frontend
1460 if (!apiKey) {
1461 return Response.json(
1462 { status: "error", message: "API Key missing in request" },
1463 { status: 400 },
1464 ); // Changed status to 400
1476 }
1477
1478 const apiUrl = new URL("https://api.socialdata.tools/twitter/search");
1479 apiUrl.searchParams.set("query", query);
1480 apiUrl.searchParams.set("type", type);
1481 if (cursor) apiUrl.searchParams.set("cursor", cursor);
1482
1483 try {
1484 const apiResponse = await fetch(apiUrl.toString(), {
1485 headers: {
1486 Authorization: `Bearer ${apiKey}`, // Use the API key from the request header
1487 Accept: "application/json",
1488 },
1491 let responseData;
1492 try {
1493 responseData = await apiResponse.json();
1494 } catch (e) {
1495 const text = await apiResponse.text();
1496 console.error("Non-JSON response from SocialData:", text);
1497 return Response.json(
1498 {
1499 status: "error",
1500 message: `SocialData API non-JSON response: ${apiResponse.statusText}`,
1501 },
1502 { status: apiResponse.status },
1503 );
1504 }
1505
1506 if (!apiResponse.ok || responseData.status === "error") {
1507 console.error(
1508 `SocialData API Error (${apiResponse.status}):`,
1509 responseData,
1510 );
1514 status: "error",
1515 message: responseData?.message
1516 || `SocialData API Error: ${apiResponse.statusText}`,
1517 },
1518 { status: apiResponse.status },
1519 );
1520 }

test01main.tsx57 matches

@tsuchi_yaUpdated 1 month ago
9 const [query, setQuery] = React.useState("");
10 const [targetAccount, setTargetAccount] = React.useState("");
11 const [apiKey, setApiKey] = React.useState("");
12 const [searchType, setSearchType] = React.useState("Latest");
13 const [sinceDate, setSinceDate] = React.useState("");
35 const checkAuth = async () => {
36 try {
37 const response = await fetch("/api/me"); // サーバーに現在のユーザー情報を問い合わせる
38 if (response.ok) {
39 const userData = await response.json(); // 応答がOKならユーザーデータを取得
57 if (!user) return; // ユーザーがログインしていない場合は何もしない(※useEffectの後に移動したのでこのチェックは不要かも)
58 try {
59 const response = await fetch("/api/searches"); // 保存済み検索APIを叩く
60 if (response.ok) {
61 const searches = await response.json();
94
95 try {
96 const response = await fetch("/api/login", {
97 // ログインAPIを叩く
98 method: "POST",
99 headers: { "Content-Type": "application/json" },
125
126 try {
127 const response = await fetch("/api/register", {
128 // 登録APIを叩く
129 method: "POST",
130 headers: { "Content-Type": "application/json" },
148 const handleLogout = async () => {
149 try {
150 await fetch("/api/logout"); // ログアウトAPIを叩く
151 setUser(null); // ユーザー情報をnullにする
152 // setSavedSearches([]); // useEffectでuserが変わると自動でクリアされるので不要
178 if (!searchName) return; // キャンセルされたら何もしない
179
180 const response = await fetch("/api/searches/save", {
181 // 保存APIを叩く
182 method: "POST",
183 headers: { "Content-Type": "application/json" },
212
213 try {
214 const response = await fetch(`/api/searches/${searchId}/delete`, {
215 method: "POST", // Val Townの制限でDELETEが使えない場合があるのでPOSTを使う
216 });
279 const fetchAllTweets = React.useCallback(
280 async (fullQuery, type, targetCount) => {
281 if (!apiKey.trim()) {
282 setError("Please enter your SocialData API Key.");
283 return;
284 }
306 params.append("cursor", currentCursor);
307 }
308 const response = await fetch(`/api/search?${params.toString()}`, {
309 headers: { "X-Api-Key": apiKey },
310 });
311 if (!isFetchingRef.current) break;
313 const errorData = await response
314 .json()
315 .catch(() => ({ message: `API Error: ${response.statusText}` }));
316 throw new Error(
317 errorData.message ||
318 `API Error: ${response.statusText} on page ${pageNum}`
319 );
320 }
323 if (data.status === "error") {
324 throw new Error(
325 data.message || `API returned an error on page ${pageNum}`
326 );
327 }
356 }
357 },
358 [apiKey]
359 );
360
365 return;
366 }
367 if (!apiKey.trim()) {
368 setError("Please enter your SocialData API Key.");
369 return;
370 }
596 )
597 ),
598 // API Key Section
599 React.createElement(
600 "div",
605 React.createElement(
606 "label",
607 { htmlFor: "apiKey", className: "label" },
608 "API Key"
609 ),
610 React.createElement("input", {
611 type: "password",
612 id: "apiKey",
613 value: apiKey,
614 onChange: (e) => setApiKey(e.target.value),
615 placeholder: "Enter SocialData API Key",
616 className: "input",
617 })
1081 rel: "noopener noreferrer",
1082 },
1083 "SocialData API"
1084 ),
1085 " | ",
1201
1202 // テーブル確認用エンドポイント
1203 if (url.pathname === "/api/check-table") {
1204 try {
1205 const result = await sqlite.execute(`
1222
1223 // ヘルパー関数テスト用エンドポイント(単純化)
1224 if (url.pathname === "/api/test-helpers") {
1225 try {
1226 // パスワードハッシュ化のテスト
1247
1248 // ユーザー登録エンドポイント
1249 if (url.pathname === "/api/register") {
1250 if (request.method !== "POST") {
1251 return Response.json({ error: "Method not allowed" }, { status: 405 });
1338
1339 // ユーザーログインエンドポイント
1340 if (url.pathname === "/api/login") {
1341 if (request.method !== "POST") {
1342 return Response.json({ error: "Method not allowed" }, { status: 405 });
1409
1410 // 現在のユーザー情報取得エンドポイント
1411 if (url.pathname === "/api/me") {
1412 try {
1413 // ユーザー情報を取得
1446
1447 // ログアウトエンドポイント
1448 if (url.pathname === "/api/logout") {
1449 return Response.json(
1450 { success: true },
1460
1461 // 検索条件保存エンドポイント
1462 if (url.pathname === "/api/searches/save") {
1463 if (request.method !== "POST") {
1464 return Response.json({ error: "Method not allowed" }, { status: 405 });
1545
1546 // 保存済み検索一覧取得エンドポイント
1547 if (url.pathname === "/api/searches") {
1548 try {
1549 // ユーザー情報を取得
1575 // 保存済み検索削除エンドポイント
1576 if (
1577 url.pathname.startsWith("/api/searches/") &&
1578 url.pathname.includes("/delete")
1579 ) {
1625 }
1626
1627 // 既存のAPI検索エンドポイント
1628 if (url.pathname === "/api/search") {
1629 const apiKey = request.headers.get("X-Api-Key");
1630 if (!apiKey) {
1631 return Response.json(
1632 { status: "error", message: "API Key missing" },
1633 { status: 401 }
1634 );
1643 );
1644 }
1645 const apiUrl = new URL("https://api.socialdata.tools/twitter/search");
1646 apiUrl.searchParams.set("query", query);
1647 apiUrl.searchParams.set("type", type);
1648 if (cursor) apiUrl.searchParams.set("cursor", cursor);
1649
1650 try {
1651 const apiResponse = await fetch(apiUrl.toString(), {
1652 headers: {
1653 Authorization: `Bearer ${apiKey}`,
1654 Accept: "application/json",
1655 },
1657 let responseData;
1658 try {
1659 responseData = await apiResponse.json();
1660 } catch (e) {
1661 const text = await apiResponse.text();
1662 console.error("Non-JSON response:", text);
1663 return Response.json(
1664 {
1665 status: "error",
1666 message: `API non-JSON response: ${apiResponse.statusText}`,
1667 },
1668 {
1669 status: apiResponse.status,
1670 }
1671 );
1672 }
1673 if (!apiResponse.ok || responseData.status === "error") {
1674 console.error(`API Error (${apiResponse.status}):`, responseData);
1675 return Response.json(
1676 {
1677 status: "error",
1678 message:
1679 responseData?.message || `API Error: ${apiResponse.statusText}`,
1680 },
1681 { status: apiResponse.status }
1682 );
1683 }

stevensDemosendDailyBrief.ts8 matches

@jasonhwestUpdated 1 month ago
97
98export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99 // Get API keys from environment
100 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
101 const telegramToken = Deno.env.get("TELEGRAM_TOKEN");
102
106 }
107
108 if (!apiKey) {
109 console.error("Anthropic API key is not configured.");
110 return;
111 }
122
123 // Initialize Anthropic client
124 const anthropic = new Anthropic({ apiKey });
125
126 // Initialize Telegram bot
162
163 // disabled title for now, it seemes unnecessary...
164 // await bot.api.sendMessage(chatId, `*${title}*`, { parse_mode: "Markdown" });
165
166 // Then send the main content
169
170 if (content.length <= MAX_LENGTH) {
171 await bot.api.sendMessage(chatId, content, { parse_mode: "Markdown" });
172 // Store the briefing in chat history
173 await storeChatMessage(
198 // Send each chunk as a separate message and store in chat history
199 for (const chunk of chunks) {
200 await bot.api.sendMessage(chatId, chunk, { parse_mode: "Markdown" });
201 // Store each chunk in chat history
202 await storeChatMessage(

stevensDemoREADME.md1 match

@jasonhwestUpdated 1 month ago
53You'll need to set up some environment variables to make it run.
54
55- `ANTHROPIC_API_KEY` for LLM calls
56- You'll need to follow [these instructions](https://docs.val.town/integrations/telegram/) to make a telegram bot, and set `TELEGRAM_TOKEN`. You'll also need to get a `TELEGRAM_CHAT_ID` in order to have the bot remember chat contents.
57- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.

stevensDemoREADME.md5 matches

@jasonhwestUpdated 1 month ago
8## Hono
9
10This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
11
12## Serving assets to the frontend
20### `index.html`
21
22The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
23
24We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
25
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
31
32Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.

stevensDemoNotebookView.tsx5 matches

@jasonhwestUpdated 1 month ago
8import { type Memory } from "../../shared/types.ts";
9
10const API_BASE = "/api/memories";
11const MEMORIES_PER_PAGE = 20;
12
71 setError(null);
72 try {
73 const response = await fetch(API_BASE);
74 if (!response.ok) {
75 throw new Error(`HTTP error! status: ${response.status}`);
100
101 try {
102 const response = await fetch(API_BASE, {
103 method: "POST",
104 headers: { "Content-Type": "application/json" },
123
124 try {
125 const response = await fetch(`${API_BASE}/${id}`, {
126 method: "DELETE",
127 });
155
156 try {
157 const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158 method: "PUT",
159 headers: { "Content-Type": "application/json" },

stevensDemoindex.ts11 matches

@jasonhwestUpdated 1 month ago
26});
27
28// --- API Routes for Memories ---
29
30// GET /api/memories - Retrieve all memories
31app.get("/api/memories", async (c) => {
32 const memories = await getAllMemories();
33 return c.json(memories);
34});
35
36// POST /api/memories - Create a new memory
37app.post("/api/memories", async (c) => {
38 const body = await c.req.json<Omit<Memory, "id">>();
39 if (!body.text) {
44});
45
46// PUT /api/memories/:id - Update an existing memory
47app.put("/api/memories/:id", async (c) => {
48 const id = c.req.param("id");
49 const body = await c.req.json<Partial<Omit<Memory, "id">>>();
66});
67
68// DELETE /api/memories/:id - Delete a memory
69app.delete("/api/memories/:id", async (c) => {
70 const id = c.req.param("id");
71 try {
83// --- Blob Image Serving Routes ---
84
85// GET /api/images/:filename - Serve images from blob storage
86app.get("/api/images/:filename", async (c) => {
87 const filename = c.req.param("filename");
88

stevensDemoindex.html2 matches

@jasonhwestUpdated 1 month ago
12 type="image/svg+xml"
13 />
14 <link rel="preconnect" href="https://fonts.googleapis.com" />
15 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
16 <link
17 href="https://fonts.googleapis.com/css2?family=Pixelify+Sans:wght@400..700&display=swap"
18 rel="stylesheet"
19 />

Galacta3 file matches

@defunktUpdated 2 hours ago
Marvel Rivals GPT via tracker.gg API

github-api2 file matches

@cricks_unmixed4uUpdated 10 hours ago
apiry
snartapi