> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# handle_request

> Dispatch one HTTP request to the service without a web framework.

[on-request]: /docs/server-sdks/reference/python/agents/swml-service/on-request

[register-routing-callback]: /docs/server-sdks/reference/python/agents/swml-service/register-routing-callback

Dispatch a request over plain values instead of FastAPI objects. Performs proxy
detection, basic auth, the [routing callback][register-routing-callback] check,
and [`on_request()`][on-request] modification, then renders the document. The
FastAPI routes delegate to the same logic, so both paths return identical
responses. Basic auth is always on: pass `basic_auth` to the constructor and
send a matching `Authorization` header, or the call returns `401`.

## Parameters

**`method`** `str` — required

HTTP method, such as `"GET"` or `"POST"`.

---

**`url`** `str` — required

The full request URL. Used for proxy detection and to match a registered
routing callback path.

---

**`headers`** `dict[str, str]` — required

Request headers as a plain dictionary.

---

**`body`** `dict[str, Any] | None` — default: None

The already-parsed JSON body for `POST` requests.

---

## Returns

`tuple[int, dict[str, str], str]` -- `(status_code, response_headers, body)`.

* `200` with the SWML document as a JSON string.
* `307` with a `Location` header and an empty body when a routing callback
  returned a destination.
* `401` with `WWW-Authenticate: Basic` and a JSON error when basic auth fails.

## Example

```python {10-15}
import base64
import json
from signalwire import SWMLService

service = SWMLService(name="greeting", route="/greeting", basic_auth=("greeting", "s3cret"))
service.add_verb("answer", {})
service.add_verb("play", {"url": "say:Welcome to Bayview Taxi."})

credentials = base64.b64encode(b"greeting:s3cret").decode()
status, headers, body = service.handle_request(
    "GET",
    "https://bayview-taxi.example.com/greeting",
    {"authorization": f"Basic {credentials}"},
)
print(status, json.loads(body)["sections"]["main"])
```