---
id: "wrap-a-listener"
type: "guide"
title: "Wrap a webhook listener"
summary: "Keep an HTTP webhook handler alive as a managed listener worker with routes on the managed HTTP context."
why: "Listeners are the fully implemented worker type in v0.1 — Servix owns the server lifecycle, health, and logs."
audiences: ["developers"]
prerequisites: ["listener-vs-proactive"]
related: ["wrap-a-function"]
---
# Wrap a webhook listener

1. Keep your existing handler:

```ts
async function handleWebhook(payload: unknown) {
  // existing logic
}
```

2. Register it on the managed HTTP context in a `listener` worker:

```ts
import { defineServixService } from "@x12i/servix";

export default defineServixService({
  name: "risk-listener",
  workers: [
    {
      id: "risk-webhook",
      type: "listener",
      async start(ctx) {
        ctx.http.post("/webhook/risk", async (req) => {
          await handleWebhook(req.body);
        });
      },
      async stop(ctx) {
        await ctx.http.close();
      }
    }
  ]
});
```

3. Run it:

```bash
servix start risk-listener
servix health risk-listener
```

Servix keeps the listener alive and manages logs, health, restart, and stop.