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/?q=api&page=804&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 10973 results for "api"(1355ms)

valBackupmain.tsx11 matches

@iamseeley•Updated 10 months ago
1import { ValTownAPI } from 'https://esm.town/v/iamseeley/ValTownAPI';
2import { GitHubAPI } from 'https://esm.town/v/iamseeley/GitHubAPI';
3
4const VAL_TOWN_API_KEY = Deno.env.get('valtown');
5const GITHUB_TOKEN = Deno.env.get("GITHUB_TOKEN");
6const GITHUB_REPO = "iamseeley/vals-backup";
7const GITHUB_BRANCH = "main";
8
9const valTownAPI = new ValTownAPI(VAL_TOWN_API_KEY);
10const gitHubAPI = new GitHubAPI(GITHUB_TOKEN);
11
12async function fetchVals() {
13 const response = await valTownAPI.getAllVals();
14 return response.data;
15}
18 console.log(`Fetching existing files from repo: ${GITHUB_REPO}, branch: ${GITHUB_BRANCH}`);
19 try {
20 const response = await gitHubAPI.getRepoContent(GITHUB_REPO, "", GITHUB_BRANCH);
21 console.log("Existing files:", response);
22 return response.map(file => file.path);
32
33 for (const file of files) {
34 const commitHistory = await gitHubAPI.getCommitHistory(GITHUB_REPO, file, GITHUB_BRANCH);
35 lastModifiedDates[file] = new Date(commitHistory[0].commit.committer.date).getTime();
36 }
46 if (fileExists) {
47 console.log(`File exists: ${filePath}`);
48 const shaResponse = await gitHubAPI.getRepoContent(GITHUB_REPO, filePath, GITHUB_BRANCH);
49 const sha = shaResponse.sha;
50 console.log(`Fetched SHA for ${filePath}: ${sha}`);
52 throw new Error(`Failed to fetch SHA for ${filePath}`);
53 }
54 await gitHubAPI.updateFile(GITHUB_REPO, filePath, fileContent, sha, commitMessage, GITHUB_BRANCH);
55 console.log(`File updated: ${filePath}`);
56 } else {
57 console.log(`File does not exist: ${filePath}`);
58 await gitHubAPI.createFile(GITHUB_REPO, filePath, fileContent, commitMessage, GITHUB_BRANCH);
59 console.log(`File created: ${filePath}`);
60 }

GitHubAPImain.tsx6 matches

@iamseeley•Updated 10 months ago
1export class GitHubAPI {
2 constructor(private token: string) {}
3
4 async getRepoContent(repo: string, path: string, branch: string) {
5 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}?ref=${branch}`, {
6 method: 'GET',
7 headers: {
18
19 async getFileSHA(repo: string, path: string, branch: string) {
20 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}?ref=${branch}`, {
21 method: 'GET',
22 headers: {
34
35 async updateFile(repo: string, path: string, content: string, sha: string, message: string, branch: string) {
36 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}`, {
37 method: 'PUT',
38 headers: {
59
60 async createFile(repo: string, path: string, content: string, message: string, branch: string) {
61 const url = `https://api.github.com/repos/${repo}/contents/${path}`;
62
63 let body: any = {
104
105 async getCommitHistory(repo: string, path: string, branch: string) {
106 const response = await fetch(`https://api.github.com/repos/${repo}/commits?path=${path}&sha=${branch}`, {
107 method: 'GET',
108 headers: {

ValTownAPImain.tsx6 matches

@iamseeley•Updated 10 months ago
1export class ValTownAPI {
2 constructor(private apiKey: string) {}
3
4 async getUserID() {
5 const response = await fetch('https://api.val.town/v1/me', {
6 method: 'GET',
7 headers: {
8 'Authorization': `Bearer ${this.apiKey}`,
9 'Content-Type': 'application/json'
10 }
21 async getAllVals() {
22 const userId = await this.getUserID();
23 const response = await fetch(`https://api.val.town/v1/users/${userId}/vals`, {
24 method: 'GET',
25 headers: {
26 'Authorization': `Bearer ${this.apiKey}`,
27 'Content-Type': 'application/json'
28 }

GitHubAPIREADME.md1 match

@iamseeley•Updated 10 months ago
1Migrated from folder: val_backup/GitHubAPI

ValTownAPIREADME.md1 match

@iamseeley•Updated 10 months ago
1Migrated from folder: val_backup/ValTownAPI

spotifymain.tsx5 matches

@anthonyec•Updated 10 months ago
25
26export let spotifyRequestToken = ({ client_id, client_secret, code, redirect_uri }) =>
27 fetchJSON("https://accounts.spotify.com/api/token", {
28 method: "POST",
29 body: querystring({
39
40export let spotifyRefreshToken = async ({ refresh_token, client_id, client_secret }) =>
41 fetch("https://accounts.spotify.com/api/token", {
42 method: "POST",
43 body: new URLSearchParams({
193
194 try {
195 const currentlyPlaying = await fetch("https://api.spotify.com/v1/me/player/currently-playing", {
196 method: "GET",
197 headers: {
209
210 if (!mostRecentTrack) {
211 const recentTracks = await fetch("https://api.spotify.com/v1/me/player/recently-played", {
212 method: "GET",
213 headers: {
234
235 try {
236 const playStateResponse = await fetch("https://api.spotify.com/v1/me/player?market=US", {
237 method: "GET",
238 headers: {

spotifymain.tsx5 matches

@niek•Updated 10 months ago
25
26export let spotifyRequestToken = ({ client_id, client_secret, code, redirect_uri }) =>
27 fetchJSON("https://accounts.spotify.com/api/token", {
28 method: "POST",
29 body: querystring({
39
40export let spotifyRefreshToken = async ({ refresh_token, client_id, client_secret }) =>
41 fetch("https://accounts.spotify.com/api/token", {
42 method: "POST",
43 body: new URLSearchParams({
193
194 try {
195 const currentlyPlaying = await fetch("https://api.spotify.com/v1/me/player/currently-playing", {
196 method: "GET",
197 headers: {
209
210 if (!mostRecentTrack) {
211 const recentTracks = await fetch("https://api.spotify.com/v1/me/player/recently-played", {
212 method: "GET",
213 headers: {
234
235 try {
236 const playStateResponse = await fetch("https://api.spotify.com/v1/me/player?market=US", {
237 method: "GET",
238 headers: {

tomatoMinnowREADME.md1 match

@nicoalbanese•Updated 10 months ago
2Use the Vercel AI SDK in your Vals.
3
4**Note**: you must add your OpenAI key to your Val Town [Env variables](https://www.val.town/settings/environment-variables) under `OPENAI_API_KEY`. If you would like to specify a different name for your API Key, you can [create a custom OpenAI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/openai#provider-instance) with the `createOpenAI` function.
5
6Prefer another AI provider? Use [any supported provider](https://sdk.vercel.ai/providers/ai-sdk-providers) by changing just two lines of code!

translateREADME.md1 match

@yawnxyz•Updated 10 months ago
1# [Translator](https://yieldray-translate.web.val.run)
2using a [public deepl api](https://deepl.deno.dev)
3
4Migrated from folder: ExamplesAndForks/translate

convertToResumeJSONmain.tsx3 matches

@iamseeley•Updated 10 months ago
3const tokenBucket = new TokenBucket(5, 1/12);
4
5export async function convertToResumeJSON(resume, apiKey) {
6 if (!tokenBucket.consume()) {
7 throw new Error("Rate limit reached. Please try again later.");
8 }
9
10 const endpoint = 'https://api.openai.com/v1/chat/completions';
11 const model = 'gpt-4';
12
138 method: 'POST',
139 headers: {
140 'Authorization': `Bearer ${apiKey}`,
141 'Content-Type': 'application/json',
142 },

daily-advice-app1 file match

@dcm31•Updated 2 days ago
Random advice app using Advice Slip API

gptApiTemplate1 file match

@charmaine•Updated 3 days ago
apiv1
papimark21