FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
std
stdrpc
Unlisted
Like
rpc
Home
Code
2
README.md
main.tsx
Branches
1
Pull requests
Remixes
1
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Sign up now
Code
/
Code
/
Search
README.md

RPC

Turn any function into an API! This lets you call a function in Val Town without manually handling a Request or Response object.

This val can be used as a replacement for the Run API, which implicitly did something similar.

Create an API from your function:

This is how you can expose a function as an API:

  1. Create an HTTP handler val
  2. Import this val
  3. Call rpc with your function as an argument

Here's an example from @std/rpc_example:

Create val
import { rpc } from "https://esm.town/v/std/rpc?v=5"; export const rpc_example = rpc(async (a: number, b: number) => { return a + b; });

Send a request to your val

You 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.

GET request

Create val
const res = await fetch("https://std-rpc_example.web.val.run/?args=[2,3]"); console.log(await res.json()); // 5

POST request

Create val
const res = await fetch("https://std-rpc_example.web.val.run/", { method: "POST", body: JSON.stringify({ args: [2, 3] }) }); console.log(await res.json()); // 5

Migrated from folder: rpc/rpc

Code
README.mdmain.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.