npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vercel-babashka

v0.1.4

Published

Babashka runtime for Vercel Serverless Functions

Downloads

72

Readme

Usage

Note: You don't need to clone the repository to use this runtime.

This section assumes you've had some experience with Vercel Serverless Functions and the officially supported runtimes.

Similar to how you'll do for the officially supported languages, you can put your functions under api/ (other directories should also work; just modify your vercel.json and bb.edn accordingly, see below). Babashka scripts within the api/ directory containing a public handler function will be served as Serverless Functions. For example, the following will live in api/hello.clj:

(ns hello)

(defn handler [event]
  (format "Hello from babashka %s!" (System/getProperty "babashka.version")))

To use this custom runtime, you'll also need the following vercel.json:

{
  "functions": {
    "api/**/*.clj": {
      "runtime": "[email protected]"
    }
  }
}

You can learn more about community runtimes here, and vercel.json options here.

Example deployment: https://vercel-babashka.vercel.app/api/hello

Other examples can be found under the api directory.

Handler Function

You've seen in the about example that the handler function is called with an event argument and returns a response. In this section we'll see more details about the argument and return value.

While in AWS Lambda where there're different types of events coming from different event sources, in Vercel Serverless Functions there doesn't seem to be event sources other than HTTP requests, so the event here will probably always look like an HTTP request from the client.

You can try this example to see how the event will look like. Basically, it is a map with the following keys:

  • :method: The HTTP method of the request. Example: "GET", "POST".
  • :host: The host of the request. Example: "vercel-babashka.vercel.app".
  • :path: The path of the request. Example: "/api/hello?q=test".
  • :headers: A map of the headers of the request where keys are converted to keywords like :content-type.
  • :encoding: A string describing the encoding of the request body. Example: "base64". Note:
    • This runtime automatically decodes base64-encoded bodies and also sets :encoding to "base64-decoded" if that's done.
    • However, if the request is a multipart/form-data one and is base64-encoded, the body will be decoded into the :decoded-body-bytes field instead, and :body and :encoding will be untouched.
  • :body: A string containing the body of the user request.
  • :params: A map populated from the query string of the request, with field names converted to keywords. nil if no query parameters supplied. Example: {:q "test"}.
  • :form-params: Like :params, but populated from the body of an application/x-www-form-urlencoded request.

The handler can either return a map or, as a simpler form, values of other arbitrary types.

If a map is returned, it should contain zero or more of the following keys:

  • :status: The HTTP status code to return. Default: 200.
  • :headers: A map of the headers to return. Example: {:content-type "text/plain"}. Keywords as values would also work.
  • :body: The response body.
    • To respond with binary data, return a byte array as the body.
    • Will be converted to a string with clojure.core/str if it's not already and not bytes.
  • :jsonify: If true, the body is converted to a string by calling json/encode on it, in contrast to using str above. Useful for creating JSON responses.

A note on the content type header: If you don't specify one, the runtime will make a guess:

  • If :jsonify is true, the content type will be "application/json".
  • If :body is a byte array, the content type will be "application/octet-stream".
  • Otherwise, the content type will be "text/plain".

If anything other than a map is returned from the handler, it will be treated as a map {:body it} and the above will apply.

bb.edn

You can optionally put a bb.edn file in the root of your project. If you don't, a default one will be used, which is just {:paths ["api"]}.

Rewriting Request Paths

The path to your handler may be in snake_case due to Clojure limitations but you may want users to call the APIs in kebab-case. You can use rewrites in your vercel.json to do that. A more detailed explanation for the options is available in the Next.js docs.

For an example, take a look at this project's vercel.json, which contains the following to allow users to access any APIs in api/any_thing using /api/any-thing:

{
  "rewrites": [
    {
      "source": "/api/:p1(.+)-:p2(.+)/:path*",
      "destination": "/api/:p1*_:p2*/:path*"
    }
  ]
}

Environment Variables

You can specify environment variables from the project settings in your browser. Currently supported environment variables are:

  • BABASHKA_INSTALL_VERSION: By default, the runtime doesn't care about the version of bb (if you're developing locally and have it installed in your system), and when deployed, the installer will install the latest version. If you want a specific version, set this variable. Example: 0.6.7.

Local Development

To do development work on this project, simply clone it, run yarn, and then vercel dev.

To use an unpublished version of this project as a custom runtime in some other project, first do npm link in this project, and in the other project, use /path/to/this/project/tools/fix_vercel_npm_install.clj vercel dev instead of vercel dev.

Acknowledgements

This runtime is heavily inspired by dainiusjocas/babashka-lambda and importpw/vercel-bash.