Documentation Index
Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Use the serve() function to define an endpoint that runs a workflow.
It accepts two arguments:
- Route Function: an async function that receives the workflow context and defines the workflow steps.
- Options: configuration options for the workflow.
import { serve } from "@upstash/workflow/nextjs";
export const { POST } = serve(async (context) => {
// Route function
}, {
// Options
});
Route Function
The route function defines the execution logic of the workflow.
It is an async function that receives a context object, which is automatically created and passed by Upstash Workflow.
The context object provides:
- Workflow APIs – functions for defining workflow steps.
- Workflow Run Properties – request payload, request headers, and other metadata.
For a full list of available APIs and properties, see the Workflow Context documentation.
import { serve } from "@upstash/workflow/nextjs";
export const { POST } = serve(
async (context) => {
// 👇 Access context properties
const { userId } = context.requestPayload;
// 👇 Define a workflow step
await context.run("step-1", async () => {})
}
);
Options
Options provide additional configuration for workflow runs.
Most of them are advanced settings and are not required for typical use cases. See Advanced Options for more details.
import { serve } from "@upstash/workflow/nextjs";
export const { POST } = serve(
async (context) => { ... },
// 👇 Workflow options
{
failureFunction: async ({ ... }) => {}
}
);