Serverless functions are at their most useful when they sit between a browser and an API that wants a credential. The client calls the function's URL, the function calls the upstream API using secrets it holds, and only the response travels back to the page. Two problems disappear at once: a purely static site can pull in data, and the API key stays out of client-side code where anyone can read it.

The proxy pattern and where to host it

Auth0's Webtask was an early demonstration of this — a small CodePen-like IDE showing only code and logs, with secrets stored for you, triggered by hitting the function URL. It is defunct now, but the shape it established persists.

AWS Lambda is the standards-setting implementation of the serverless function, and the AWS console includes an online editor for it, though working directly in the console is rarely pleasant. Functions in AWS Amplify are a better route on that platform. Other current options:

  • Build, test and deploy functions with Serverless.com's framework.
  • Netlify Functions, paired with Netlify Dev.
  • Vercel's Serverless Functions, or Next.js /pages/api routes on any Node host such as Heroku.

Tools that look promising but are harder to assess: Begin.com, SLAppForge, and Deno, the next-generation server-side JavaScript runtime, which is moving into deployment as a service.

Pipedream: code-first with many triggers

Pipedream is a web-based IDE for writing functions, but the trigger surface extends well beyond a URL. Functions can run on a CRON schedule or be fired by events such as email or RSS, and integrations include Slack, GitHub and Twitter. The trigger list resembles Zapier's, except that Zapier is entirely no-code while Pipedream treats code as a first-class citizen.

Secrets are handled through account-level environment variables.

The Pipedream screen for environment variables. A dark gray sidebar is on the left with different menu options where Settings is the currently selected item in the vertical list. The right side of the screen contains the environment variable information with a paragraph defining them, an example, then a bright blue button to create a new environment variable.

Why it fits

As Raymond Camden describes the appeal, an API that requires authentication — an API key, say — cannot be called from client-side JavaScript without exposing that key to anyone who views the source. Some services let you lock a key to a domain, but where that option is missing, a serverless function provides an endpoint that makes the call with the key held server-side. Pipedream's trigger and secrets model makes it well suited to that proxy role; Camden's post covers the implementation and code examples.