Sign In
Getting Started

Rivet Functions

Rivet Functions allows you to deploy serverless functions that can handle HTTP requests. You can write your functions and package them in containers.


What are functions good for?

  • API Endpoints: Building lightweight, scalable REST or GraphQL APIs. For example, CRUD Operations for your application's data layer.
  • Webhook Handlers: Processing events from third-party services. For example, Payment Processing with Stripe or PayPal integration.
  • Authentication Services: Managing user identity and access control. For example, OAuth Flows or custom authentication systems.

Quickstart

1. Set up your project

Let's create a simple Node.js HTTP server project:

Command Line
# Create project
mkdir my-rivet-function
cd my-rivet-function

# Setup NPM
npm init -y
npm install hono

Add the following files:

{
  "functions": {
    "hello-world": {
      "dockerfile": "Dockerfile"
    }
  }
}

See Containers documentation for more information on writing code for the Rivet platform.

2. Deploy your function

Command Line
rivet deploy

You will be prompted to configure a route on the first run. You can use the recommended route or configure it later in the dashboard under the Functions tab.

3. Test your function

Visit your function at the configured URL. You can monitor the logs in the Logs tab of the Rivet Dashboard.


Configuration Options

Basic Configuration

OptionDescription
pathThe URL path to route requests to (cannot end with /)
route_subpathsWhen true, routes requests to this path and all nested subpaths to this function
strip_prefixWhen true, removes the configured path prefix from the request URL before forwarding to your function
resources.cpuCPU allocation for the function (defaults to 1)
resources.memoryMemory allocation in MB (defaults to 1024)
networking.internal_portThe port your function listens on within the container

Example: route_subpaths

When route_subpaths is true:

  • Function with path /api will handle requests to /api, /api/users, /api/products, and any other path starting with /api

When route_subpaths is false:

  • Function with path /api will only handle requests to the exact path /api and nothing else

Example: strip_prefix

When strip_prefix is true:

  • Request to /api/users will be forwarded to your function as just /users (the /api prefix is removed)

When strip_prefix is false:

  • Request to /api/users will be forwarded to your function with the full path /api/users intact

See the Configuration Reference for the complete configuration options.

When you make changes to your routes, the rivet deploy command will prompt you before applying these changes to how your requests get routed.


Routes (Advanced)

Routes configure how incoming HTTP traffic gets directed to the specific function workers that handle requests. They define the mapping between public URLs and your deployed functions. Routes can be manually configured in the Functions tab of the Rivet Dashboard.

Hostnames

Each route has a unique hostname (URL), and these hostnames cannot be shared across multiple environments.

Path Matching

Routing priority is determined by path length with longest paths matching first. You can layer multiple paths to create sophisticated routing patterns.

Programmatic Creation

Routes can be created programmatically via the Rivet API with routes.update.

Suggest changes to this page