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/$2?q=api&page=1459&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 18008 results for "api"(3889ms)

googleCalendarWeekEndpointmain.tsx3 matches

@ejfox•Updated 9 months ago
8const REDIRECT_URI = Deno.env.get("REDIRECT_URI"); // Should be set to your Val Town endpoint URL + "/callback"
9
10const SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"];
11
12export default async function server(request: Request): Promise<Response> {
46
47 // Exchange code for tokens
48 const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
49 method: "POST",
50 headers: {
68
69 const calendarResponse = await fetch(
70 `https://www.googleapis.com/calendar/v3/calendars/primary/events?` +
71 `timeMin=${now.toISOString()}` +
72 `&timeMax=${oneWeekLater.toISOString()}` +

VALLEREADME.md3 matches

@heaversm•Updated 9 months ago
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
11
12<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>

valleBlogV0README.md1 match

@heaversm•Updated 9 months ago
1* Fork this val to your own profile.
2* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
3

valleBlogV0main.tsx1 match

@heaversm•Updated 9 months ago
38 model: openai("gpt-4o", {
39 baseURL: "https://std-openaiproxy.web.val.run/v1",
40 apiKey: Deno.env.get("valtown"),
41 } as any),
42 messages: [

ReactStreamREADME.md4 matches

@lisardo•Updated 9 months ago
36
37Custom middleware can be added in an array as the third argument.
38Middleware can add data to the `req.data` object or return a response for things like API endpoints.
39
40```tsx
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65 if (req.pathname !== "/api") return next();
66 if (req.method === "POST") {
67 return Repsonse.json({ message: "Hello POST request" });
70}
71
72export default render(App, import.meta.url, [ api ]);
73```
74

ReactStreammain.tsx7 matches

@lisardo•Updated 9 months ago
34 const useMiddleware = Array.isArray(opts); // for backwards compat
35 const options: ReactStreamOptions = !Array.isArray(opts) ? opts : {};
36 const { api, getInitialProps } = options;
37
38 if (typeof document !== "undefined" && module) {
48 // DEPRECATED (for backwards compat)
49 options.robots && robots(options.robots),
50 options.api && deprecatedCustomAPI(options.api),
51 options.getInitialProps && deprecatedGetInitiaProps(options.getInitialProps),
52 // New custom middleware
127// DEPRECATED
128// DEPRECATE (for backwards compat)
129const deprecatedCustomAPI = (api?: RequestHandler): Middleware => async (req, res, next) => {
130 if (!api) return next();
131 if (req.method === "GET") return next();
132 return api(req);
133};
134const deprecatedGetInitiaProps = (getProps: DataFetcher<any>): Middleware => async (req, res, next) => {
142 /** DEPRECATED: Optional text response for robots.txt */
143 robots?: string;
144 /** DEPRECATED: Optional API request handler for all non-GET methods */
145 api?: RequestHandler;
146 /** DEPRECATED: data fetcher to set initial props based on request */
147 getInitialProps?: DataFetcher<any>;

endpointCalculatormain.tsx1 match

@ejfox•Updated 9 months ago
1/**
2 * This program creates a basic calculator endpoint that accepts and returns data in the specified format.
3 * It uses a RESTful API approach where the operation is specified in the URL path.
4 * The numbers to operate on are passed as query parameters.
5 * The result is returned as JSON.

untitled_azureWhippetmain.tsx1 match

@jordonezrodri2•Updated 9 months ago
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
8 return response.json();

hungryWhiteLeoponmain.tsx10 matches

@gr8gatsby•Updated 9 months ago
1/**
2 * This application helps users write detailed reviews of coffee shops. It fetches coffee shop data
3 * from the OpenStreetMap Nominatim API, allows users to add custom details, and stores the augmented
4 * information in a SQLite database. The app provides a user interface to view, add, and edit coffee shop reviews.
5 *
6 * It uses React for the frontend, the Nominatim API for initial coffee shop data,
7 * and Val Town's SQLite for data persistence.
8 */
30 const fetchCoffeeShops = async () => {
31 try {
32 const response = await fetch(`/api/coffee-shops?search=${encodeURIComponent(searchTerm)}`);
33 if (!response.ok) throw new Error("Failed to fetch coffee shops");
34 const data = await response.json();
41 const fetchReviews = async () => {
42 try {
43 const response = await fetch("/api/reviews");
44 if (!response.ok) throw new Error("Failed to fetch reviews");
45 const data = await response.json();
60
61 try {
62 const response = await fetch("/api/reviews", {
63 method: "POST",
64 headers: { "Content-Type": "application/json" },
192 console.log("Table checked/created successfully");
193
194 if (url.pathname === "/api/coffee-shops") {
195 const searchTerm = url.searchParams.get("search") || "";
196 // Fetch coffee shops from OpenStreetMap Nominatim API
197 const nominatimUrl = `https://nominatim.openstreetmap.org/search?q=coffee+${
198 encodeURIComponent(searchTerm)
204 });
205 if (!nominatimResponse.ok) {
206 throw new Error(`Nominatim API error! status: ${nominatimResponse.status}`);
207 }
208 const nominatimData = await nominatimResponse.json();
209 if (!Array.isArray(nominatimData)) {
210 throw new Error("Invalid data received from Nominatim API");
211 }
212 const coffeeShops = nominatimData.map((shop: any) => ({
221 }
222
223 if (url.pathname === "/api/reviews") {
224 if (request.method === "GET") {
225 const reviews = await sqlite.execute(`SELECT * FROM ${KEY}_coffee_reviews_${SCHEMA_VERSION}`);

addToLogmain.tsx2 matches

@ejfox•Updated 9 months ago
63 </div>
64 <a href={import.meta.url.replace("esm.town", "val.town")} target="_blank" rel="noopener noreferrer" className="view-source">View Source</a>
65 <pre className="api-examples">
66{`// Axios example
67const axios = require('axios');
214 text-decoration: underline;
215}
216.api-examples {
217 margin-top: 20px;
218 background-color: #f0f0f0;

Apiify7 file matches

@wolf•Updated 49 mins ago

dailyQuoteAPI

@Souky•Updated 2 days ago
Kapil01
apiv1