You can access search results via JSON API by adding format=json
to your query:
https://codesearch.val.run/$%7Bsuccess?q=api&page=51&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 15513 results for "api"(1512ms)
1# Val Town Docs - HTTP Examples
23HTTP triggers let you expose an API or website from your file.
45They are built on the web-standard
6[Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and
7[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects,
8so are compatible with a number of web frameworks like
9[Hono](https://hono.dev/) and [Peko](https://github.com/sejori/peko).
1export default async function(req: Request) {
2try {
3const apiKey = Deno.env.get("VALTOWN_API_TOKEN");
45if (!apiKey) {
6return new Response(
7JSON.stringify({ error: "VALTOWN_API_TOKEN not found" }, null, 2),
8{ status: 400, headers: { "Content-Type": "application/json" } },
9);
1112// Get my vals using the authenticated /me/vals endpoint
13const valsResponse = await fetch("https://api.val.town/v2/me/vals", {
14headers: {
15"Authorization": `Bearer ${apiKey}`,
16"Content-Type": "application/json",
17},
20if (!valsResponse.ok) {
21const errorText = await valsResponse.text();
22console.log("API Error response:", errorText);
23throw new Error(
24`Failed to fetch vals: ${valsResponse.status} ${valsResponse.statusText}. Response: ${errorText}`,
42for (const val of vals) {
43try {
44// Use the files API to get the actual file structure
45const filesResponse = await fetch(
46`https://api.val.town/v2/vals/${val.id}/files?path=&recursive=true&limit=100`,
47{
48headers: {
49"Authorization": `Bearer ${apiKey}`,
50"Content-Type": "application/json",
51},
80// Fetch the file content using the file path
81const fileContentResponse = await fetch(
82`https://api.val.town/v2/vals/${val.id}/files?path=${encodeURIComponent(endpointsFile.path)}`,
83{
84headers: {
85"Authorization": `Bearer ${apiKey}`,
86"Content-Type": "application/json",
87},