17[🔬️ inspect ASP JWT token](https://vladimyr-aspe_inspector.web.val.run/aspe:keyoxide.org:TOICV3SYXNJP7E4P5AOK5DHW44)
18
19Badge with new ASPE URI (not functional yet ⚠️):
20[](https://keyoxide.org/aspe:fe7b75c54b95ac019dd48fbefe8d654af383cbfe)
21
2const VALTOWN_TOKEN = Deno.env.get("valtown");
3
4export function rpc(fn: Function, isPrivate: boolean = false) {
5 return async (req: Request): Promise<Response> => {
6 if (isPrivate) {
11});
12
13async function getKnownThreads() {
14 const result = await db.select().from(threadsTbl);
15 return result.reduce((r, { id, last_message_id }) => {
19}
20
21async function getNewThreads() {
22 const resp = await fetch(`https://discord.com/api/guilds/${guild}/threads/active`, {
23 headers: {
34}
35
36export async function getThreadsActivity(
37 token: string,
38 guild: string,
3import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
4
5export default async function(ctx: BrowserContext<{ author: string; name: string }>) {
6 const { author, name } = ctx.params;
7 const title = `@${author}/${name}`;
1# RPC
2
3Turn any function into an API! This lets you call a function in Val Town without manually handling a `Request` or `Response` object.
4
5This val can be used as a replacement for the Run API, which implicitly did something similar.
6
7## Create an API from your function:
8
9This is how you can expose a function as an API:
10
111. Create an HTTP handler val
122. Import this val
133. Call `rpc` with your function as an argument
14
15Here's an example from @std/rpc_example:
34## Send a request to your val
35
36You can invoke that function from your client or your local machine with an HTTP request. You can either use a GET or a POST request, passing arguments in the query parameters or the body respectively. Make sure your val's privacy is set to Unlisted or Public.
37
38**GET request**
1import { html } from "https://esm.town/v/stevekrouse/html?v=5";
2
3export default function() {
4 return html(`
5 <body
61});
62
63async function findMyArticles() {
64 let { data: articles } = await api(`/v1/search/vals?query=${encodeURIComponent("#blog")}`);
65
5import { html } from "https://esm.town/v/stevekrouse/html?v=5";
6
7export async function exampleArticle(req: Request) {
8 const { author, name } = extractValInfo(import.meta.url);
9
1export function extractMetadata(name: string, code: string) {
2 const regex = `// ${name}: (.+)`;
3 const match = code.match(regex);
12import { JSX } from "npm:react";
13
14export async function emailSubscription(req: Request) {
15 const app = new Hono();
16
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",