HTTP Trigger
Trigger workflows via standard HTTP requests
HTTP Trigger
The HTTP trigger allows you to initiate workflows by sending standard HTTP requests. It supports various HTTP methods and optional HMAC signature validation.
Installation
pnpm add @stepflowjs/trigger-httpUsage
import { HttpTrigger } from "@stepflowjs/trigger-http";
const trigger = new HttpTrigger({
path: "/webhooks/order",
method: "POST",
validateSignature: {
header: "x-signature",
secret: process.env.WEBHOOK_SECRET,
algorithm: "sha256",
},
});
await trigger.start(async (event) => {
console.log("Received HTTP event:", event.data);
await stepflow.trigger("process-order", event.data);
});Framework Integration
The HttpTrigger provides a handleRequest method that accepts a web-standard Request object and returns a Response object. This makes it easy to integrate with various frameworks.
Hono
app.post("/webhooks/order", async (c) => {
const response = await trigger.handleRequest(c.req.raw);
return response;
});Express
app.post("/webhooks/order", async (req, res) => {
const request = new Request(`http://localhost${req.url}`, {
method: req.method,
headers: req.headers as any,
body: JSON.stringify(req.body),
});
const response = await trigger.handleRequest(request);
res.status(response.status).json(await response.json());
});Configuration
| Option | Type | Description |
|---|---|---|
path | string | The route path for this trigger |
method | "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | HTTP method to accept |
validateSignature | object | Optional signature validation configuration |
validateSignature.header | string | Header name containing the signature |
validateSignature.secret | string | Secret key for signature verification |
validateSignature.algorithm | "sha256" | "sha1" | Hash algorithm to use |