> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# onRequest

> Public hook called on every inbound request before SWML rendering.

[on-swml-request]: /docs/server-sdks/reference/typescript/agents/agent-base/on-swml-request

[set-on-request-callback]: /docs/server-sdks/reference/typescript/agents/swml-service/set-on-request-callback

Public hook called on every inbound request before the SWML document is
rendered. The default implementation delegates to
[`onSwmlRequest()`][on-swml-request]. Override it to return a dictionary of SWML
modifications, or `void` to render with the default behavior.

Most subclasses override [`onSwmlRequest()`][on-swml-request] instead, which is
the conventional per-request customization hook. `onRequest` is the lower-level
`WebMixin` parity entry point.

This hook returns a dictionary of SWML *modifications* to merge into the
rendered document. To replace the entire SWML document for a request instead,
use [`setOnRequestCallback()`][set-on-request-callback] on `SWMLService`.

## **Parameters**

The parsed request body. Contains call metadata such as `call_id` and
`caller_id_number`.

Optional callback path from the request.

## **Returns**

`Record<string, unknown> | void` (or a `Promise` of these) -- A dict of SWML
modifications to merge before rendering, or `void` for default rendering.

## **Example**

```typescript {6}
import { AgentBase } from '@signalwire/sdk';

class PersonalizedAgent extends AgentBase {
  override async onRequest(
    requestData?: Record<string, unknown> | null,
  ): Promise<Record<string, unknown> | void> {
    const caller = (requestData?.caller_id_number as string) ?? 'unknown';
    return { global_data: { caller_number: caller } };
  }
}

const agent = new PersonalizedAgent({ name: 'personalized', route: '/' });
await agent.serve();
```