Async HTTP API endpoints
Transform synchronous HTTP requests into durable jobs so clients can fire-and-forget while still getting reliable completion updates.
Python example coming soon.
Problem
Traditional REST endpoints either block clients until work completes or require bespoke status polling code that can easily get out of sync.
If a server crashes mid-request, clients have no reliable way to know whether work finished, failed, or needs to be retried.
Solution
Resonate turns each inbound request into a durable workflow. The request handler enqueues work and immediately returns an identifier that clients can poll for status. Work execution becomes resilient to server restarts, retries, and long-running tasks.
The example demonstrates how to expose submission and status endpoints, push long-running work into Resonate, and notify clients when it completes.
Quick example
- TypeScript
app.post("/jobs", async (req, res) => {
const run = await resonate.workflows.beginRun("asyncHttpWorkflow", req.body);
res.status(202).json({ runId: run.id });
});
export function* asyncHttpWorkflow(ctx: Context, payload: JobPayload) {
const result = yield ctx.run(doWork, payload);
yield ctx.run(notifyClient, result);
}
app.get("/jobs/:id", async (req, res) => {
const status = await resonate.runs.get(req.params.id);
res.json(status);
});