serve

View as MarkdownOpen in Claude

Start a FastAPI/Uvicorn web server that serves the SWML document over HTTP. This is a blocking call that runs the server until it is stopped. The server responds to both GET and POST requests at the configured route, returning the current SWML document as JSON.

On startup, the server prints the service URL and authentication credentials to the console. If routing callbacks are registered, their endpoint URLs are also displayed.

serve() blocks the current thread. For production deployments, consider using as_router() to integrate into an existing ASGI application instead.

Parameters

host
Optional[str]Defaults to None

Host to bind to. Overrides the value set in the constructor. When None, uses the constructor’s host value.

port
Optional[int]Defaults to None

Port to bind to. Overrides the value set in the constructor. When None, uses the constructor’s port value.

ssl_cert
Optional[str]Defaults to None

Path to an SSL certificate file. Overrides the SWML_SSL_CERT_PATH environment variable.

ssl_key
Optional[str]Defaults to None

Path to an SSL private key file. Overrides the SWML_SSL_KEY_PATH environment variable.

ssl_enabled
Optional[bool]Defaults to None

Explicitly enable or disable SSL. Overrides the SWML_SSL_ENABLED environment variable.

domain
Optional[str]Defaults to None

Domain name for the SSL certificate. Used for URL generation when SSL is enabled.

Returns

None — This method blocks until the server is stopped.

Example

1from signalwire import SWMLService
2
3service = SWMLService(name="my-service", route="/swml")
4service.add_verb("answer", {})
5service.add_verb("play", {"url": "https://example.com/welcome.mp3"})
6
7# Start on default host/port (0.0.0.0:3000)
8service.serve()
9
10# Or override host and port
11# service.serve(host="127.0.0.1", port=8080)