asRouter

View as MarkdownOpen in Claude

Return the underlying Hono app for this service. This is a Python-compat alias for getApp() — use either name interchangeably. Pick asRouter() when porting code from the Python SDK that called as_router() for a FastAPI APIRouter.

Use this to mount the service into an existing Hono application rather than running a standalone server with run() or serve().

Use asRouter() for production deployments where you want to control the HTTP server lifecycle, or when hosting multiple services on the same Hono instance via AgentServer.

Returns

Hono — the configured Hono app with all routes registered (SWML document endpoint plus any routing-callback paths).

Example

1import { Hono } from 'hono';
2import { serve } from '@hono/node-server';
3import { SWMLService } from '@signalwire/sdk';
4
5const app = new Hono();
6
7const service = new SWMLService({ name: 'ivr', route: '/ivr' });
8service.addVerb('answer', {});
9service.addVerb('play', { url: 'https://example.com/welcome.mp3' });
10
11app.route('/ivr', service.asRouter());
12
13serve({ fetch: app.fetch, port: 3000 });