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/$%7Bart_info.art.src%7D?q=api&page=1508&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 17947 results for "api"(1618ms)

ideasREADME.md3 matches

@stevekrouse•Updated 1 year ago
11It would be awesome if we built a fork of these downtime detectors that also stored historical uptime/downtime (and possibly latency) information in sqlite, and then provided an http interface to view the data as well.
12
13### Free Stock API Proxy
14
15I have been working on a stock price api tool, initially for use within Google Sheets: https://www.val.town/v/stevekrouse/stockPrice
16
17It would be awesome to expand this to also be useful to other folks, ie folks within Val Town. For example, it could be used to build stock price trackers. Our [BTC price tracker](https://www.val.town/v/stevekrouse/btcPriceAlert) is pretty popular. I think one for stocks would be similarly popular, but it'd need someone to provide a good free stock API. Maybe one exists or maybe we need to proxy it.
18
19

key_safe_linkREADME.md2 matches

@stevekrouse•Updated 1 year ago
1# One-click environment variable
2
3Copying and pasting secret API keys into your Val Town [Environment Variables](https://www.val.town/settings/environment-variables) is annoying and error prone. Wouldn't it be nice if you could add an environment variable in one click? What could such a protocol look like for third-party API company to be able to safely pass their customer's API keys to their customer's Val Town account.
4
5A naive approach to this would be a link that looks like this:
11```
12
13However it isn't safe to put API key values in URLs like that, but it would be great if we could still put it in the URL so it can act like a simple link. We need to encrypt the API key in such a way that nobody can read it except for the Val Town app. Val Town could provide a public key for API providers to encrypt their tokens with.
14
15We could add an extra layer of security by including the timestamp in the request as well as the Val Town username that the token is intended for. All that data should be included in the encrypted package. We can also ensure that each such link is used exactly once.

weatherGPTmain.tsx1 match

@jcoleman•Updated 1 year ago
12 baseURL: PORTKEY_GATEWAY_URL,
13 defaultHeaders: createHeaders({
14 apiKey: Deno.env.get("PORTKEY_API_KEY"),
15 virtualKey: Deno.env.get("PORTKEY_OPENAI_VIRTUAL_KEY"),
16 }),
1This val is part of the SteamPlaytimeHistory project which consists of logging your recently played games on steam everyday through valve's API.
2
3I wanted to log this data so I can analyse which days do I game the most ? which periods do I log the most hours in my confort game (Dead By Daylight) ? And so on. I think the data viz possibilities are super interesting, just like when Valve releases the "Steam in review" at the end of the year
4
5This val fetches your recent playtime history from valve's API and stores it in a database every day !
6
7The project uses multiple vals to work:
15To run this project, you'll need:
16
17- A steam web api key: https://steamcommunity.com/login/home/?goto=%2Fdev%2Fapikey
18- SteamID of the user (profile needs to be public)
19- Discord websocket url (for error messages)

blob_adminREADME.md1 match

@bjtitus•Updated 1 year ago
9[![](https://stevekrouse-button.express.val.run/Install)](https://www.val.town/v/stevekrouse/blob_admin_app/fork)
10
11It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
12
13# TODO

gameIdeaApimain.tsx19 matches

@xkonti•Updated 1 year ago
1import { blob } from "https://esm.town/v/std/blob";
2import { extractHttpEndpoint } from "https://esm.town/v/xkonti/extractHttpEndpoint?v=2";
3import { GptApi } from "https://esm.town/v/xkonti/gptApiFramework?v=67";
4import { z } from "npm:zod";
5
6const api = new GptApi({
7 url: extractHttpEndpoint(import.meta.url).toLowerCase(),
8 title: "Video Game Idea API",
9 description: "The API for submitting fun Video Game Ideas",
10 version: "1.0.0",
11 policyGetter: async () => {
28}).describe("A Video Game Idea returned in exchange for the submitted one");
29
30api.jsonToJson({
31 verb: "post",
32 path: "/submission",
35 requestSchema: IdeaSubmissionSchema,
36 responseSchema: IdeaResponseSchema,
37}, async (ctx, input, apiKey) => {
38 if (apiKey == null || apiKey !== Deno.env.get("GPT_GAME_IDEA_API_KEY")) {
39 return {
40 idea: "",
61 : {
62 idea: "Please come up with some cool idea for the user. There is nothing in the database yet.",
63 author: "API Server",
64 };
65
79});
80
81export default api.serve();
82
83// Idea management
105}
106
107const privacyPolicy = `# Video Game Idea API Privacy Policy
108Last Updated: 2024-05-19
109
110## 1. Introduction
111Welcome to Video Game Idea API. This privacy policy outlines our practices regarding the collection, use, and sharing of information through Video Game Idea API.
112
113## 2. Data Collection and Use
114Video Game Idea API allows users to store, retrieve, list, and delete data. The data stored can be of any type as inputted by the user. We do not restrict or control the content of the data stored. Video Game Idea API serves as a public database accessible to anyone with an API key. The API is not intended for storing any personal data.
115
116## 3. User Restrictions
117Video Game Idea API does not impose age or user restrictions. However, the API is not intended for use by children under the age of 13. Users are advised to consider the sensitivity of the information they share.
118
119## 4. Global Use
120Our API is accessible globally. Users from all regions can store and access data on Video Game Idea API.
121
122## 5. Data Management
123Given the nature of Video Game Idea API, there are no user accounts or user identification measures. The API operates like a public database where data can be added, viewed, and deleted by any user. Users should be aware that any data they input can be accessed, modified, or deleted by other users.
124
125## 6. Data Security
126Video Game Idea API is protected by an API key; beyond this, there is no specific data security measure in place. Users should not store sensitive, personal, or confidential information using Video Game Idea API. User's ideas are stored in a secure manner and are not shared with any third parties. We assume no responsibility for the security of the data stored.
127
128## 7. Third-Party Involvement
129The API code is run and data is stored by val.town. They act as a third-party service provider for Video Game Idea API.
130
131## 8. Use Restrictions
132The API is not intended for use in any mission-critical applications. By submitting ideas, users are responsible for the content they submit. The ideas submitted by the user will be considered public domain.
133
134## 9. Disclaimer
135The API is provided as-is without any guarantees.
136
137## 10. Changes to This Policy

gptApiTemplatemain.tsx13 matches

@xkonti•Updated 1 year ago
1import { blob } from "https://esm.town/v/std/blob";
2import { extractHttpEndpoint } from "https://esm.town/v/xkonti/extractHttpEndpoint?v=2";
3import { GptApi } from "https://esm.town/v/xkonti/gptApiFramework?v=67";
4import { z } from "npm:zod";
5
6// Configure API
7
8const api = new GptApi({
9 url: extractHttpEndpoint(import.meta.url).toLowerCase(),
10 title: "API Name",
11 description: "The API for submitting fun Video Game Ideas",
12 version: "1.0.0",
13 policyGetter: async () => {
27}).describe("Description of the output");
28
29api.jsonToJson({
30 verb: "post",
31 path: "/example",
34 requestSchema: InputSchema,
35 responseSchema: OutputSchema,
36}, async (ctx, input, apiKey) => {
37 // Implementation of the /example endpoint
38 return {
41});
42
43// Serve the API
44export default api.serve();
45
46// Privacy policy template in Markdown
47const privacyPolicy = `# <apiName> Privacy Policy
48Last Updated: <lastUpdated>
49
50## 1. Introduction
51Welcome to <apiName>. This privacy policy outlines our practices regarding the collection, use, and sharing of information through <apiName>.
52
53## 2. Data Collection and Use
54<apiName> allows users to store, retrieve, list, and delete data. The data stored can be of any type as inputted by the user. We do not restrict or control the content of the data stored. The API operates as a public database, where data can be accessed by any user. We do not tie or track data per user.
55
56## 3. Data Security
57<apiName> is protected by an API key. Users should be aware that any data they input can be accessed, modified, or deleted by other users with access to the API key. Users are advised not to store sensitive, personal, or confidential information. We assume no responsibility for the security of the data stored. The API code is run and data is stored by val.town, a third-party service provider.
58
59## 4. Changes to This Policy

extractHttpEndpointREADME.md1 match

@xkonti•Updated 1 year ago
4
5```typescript
6const apiUrl = extractHttpEndpoint(import.meta.url);
7```

gptApiFrameworkmain.tsx43 matches

@xkonti•Updated 1 year ago
55
56/**
57 * The API info object that is used to describe the API to the GPT.
58 */
59export interface ApiInfo {
60 /**
61 * The URL of the API. This should match the URL of your Val.
62 */
63 url: string;
64
65 /**
66 * The name of the API. It gives the GPT an idea about the purpose of the API.
67 */
68 title: string;
69
70 /**
71 * A short description of the API. It gives the GPT an idea about the purpose of the API.
72 */
73 description: string;
74
75 /**
76 * The version of the API. Required by the OpenAPI spec.
77 */
78 version: string;
93 return zodToJsonSchema(schema, {
94 name: "schema",
95 target: "openApi3",
96 }).definitions?.schema ?? null;
97}
125
126/**
127 * Describes the paths of an OpenAPI spec.
128 */
129type Paths = {
136
137/**
138 * Assembles the paths of an OpenAPI spec from endpoint definitions.
139 * @param endpoints The endpoint definitions to use.
140 * @returns The paths of the OpenAPI spec.
141 */
142function getPathsDesc(endpoints: EndpointDefinition[]): Paths {
178
179/**
180 * Generates an OpenAPI spec for the defined API.
181 * @param url The URL of the API.
182 * @param title The title of the API.
183 * @param description The description of the API.
184 * @param version The version of the API.
185 * @param endpoints The endpoint definitions to use.
186 * @returns The OpenAPI spec.
187 */
188function getOpenApiSpec(
189 url: string,
190 title: string,
194) {
195 return {
196 openapi: "3.1.0",
197 info: {
198 title,
210
211/**
212 * A class representing a GPT API. It provides methods for registering
213 * endpoints and serving the API.
214 */
215export class GptApi {
216 private app = new Hono();
217 private info: ApiInfo;
218 private endpoints: EndpointDefinition[] = [];
219
220 /**
221 * Creates a new GptApi instance.
222 * @param info Configuration for the API.
223 */
224 constructor(info: ApiInfo) {
225 this.info = info;
226 this.app.get("/gpt/schema", (ctx) => {
227 const spec = getOpenApiSpec(
228 this.info.url,
229 this.info.title,
250
251 this.app.get("/", (ctx) => {
252 return ctx.text(`OpenAPI spec: ${this.info.url}/gpt/schema\nPrivacy policy: ${this.info.url}/privacypolicy\n`);
253 });
254 }
262 jsonToNothing<TRequestSchema extends z.Schema>(
263 endpointDef: InEndpointDefinition<TRequestSchema>,
264 handler: (ctx: Context, reqBody: z.infer<TRequestSchema>, apiKey: string | null) => Promise<number>,
265 ) {
266 const handlerWrapper = async (ctx: Context) => {
271 // TODO: Handle invalid data format
272
273 const apiKey = this.extractApiKey(ctx);
274 const statusCode = await handler(ctx, parsedRequestData, apiKey);
275 return ctx.body(null, statusCode as StatusCode);
276 };
294 nothingToJson<TResponseSchema extends z.Schema>(
295 endpointDef: OutEndpointDefinition<TResponseSchema>,
296 handler: (ctx: Context, apiKey: string | null) => Promise<z.infer<TResponseSchema>>,
297 ) {
298 const handlerWrapper = async (ctx: Context) => {
299 const apiKey = this.extractApiKey(ctx);
300 const response = await handler(ctx, apiKey);
301
302 // Validate response data
327 ctx: Context,
328 reqBody: z.infer<TRequestSchema>,
329 apiKey: string | null,
330 ) => Promise<z.infer<TResponseSchema>>,
331 ) {
338 // TODO: Handle invalid data format
339
340 const apiKey = this.extractApiKey(ctx);
341 const response = await handler(ctx, parsedRequestData, apiKey);
342
343 // Validate response data
388
389 /**
390 * Returns a function that can be used to serve the API.
391 *
392 * @example ValTown usage:
393 * ```ts
394 * export default gptApi.serve();
395 * ```
396 *
397 * @example Deno usage:
398 * ```
399 * const { fetch } = gptApi.serve();
400 * export default { fetch };
401 * ```
406
407 /**
408 * Extracts API key from Bearer Auth header.
409 */
410 private extractApiKey(ctx: Context): string | null {
411 const authHeader = ctx.req.header("Authorization");
412 if (!authHeader || !authHeader.startsWith("Bearer ")) {
414 }
415
416 const apiKey = authHeader.split(" ")[1];
417 return apiKey;
418 }
419}

maroonArmadilloREADME.md1 match

@stevekrouse•Updated 1 year ago
1# Hono
2
3Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It works great!
4
5

dailyQuoteAPI

@Souky•Updated 1 day ago

HTTP

@Ncharity•Updated 1 day ago
Daily Quote API
Kapil01
apiv1