# Request and response

Every field of the request your handler receives and the response it returns.

## Handler signatures

```js JavaScript
export async function handler(req) { return { status: 200, body: {} }; }
```

```python Python
def handler(req):           # or: async def handler(req)
    return {"status": 200, "body": {}}
```

In Python, `req` is a dict: use `req["query"]`, `req["body"]`.

## Request

| Field | Type | Description |
| --- | --- | --- |
| `method` | string | `GET`, `POST`, `PUT`, `PATCH` or `DELETE` |
| `path` | string | The path after the host, e.g. `/orders/1042` |
| `subpath` | string | The path after the function name, e.g. `/1042` (empty when none) |
| `query` | object | Query parameters as strings |
| `headers` | object | Request headers with lower-case names |
| `body` | any | Parsed JSON for JSON requests, otherwise text, or `null` |
| `rawBody` | string | The body as received; base64 when `isBase64Encoded` |
| `isBase64Encoded` | boolean | Whether `rawBody` is base64 (binary bodies) |
| `mode` | string | `"test"` for `?test` requests, otherwise `"live"` |
| `ip` | string | The caller's IP address |
| `apiKey` | object? | `{ id, name }` when the project [requires API keys](/api-keys) |
| `caller` | object? | `{ projectId, kind }` for calls from your own code (`kind`: `endpoint` for your project's code, `schedule`, `mcp` or `console`) |

The `test` query parameter is removed from `query`.

## Response

| Field | Type | Description |
| --- | --- | --- |
| `status` | number | HTTP status. Defaults to 200. |
| `headers` | object | Response headers |
| `body` | any | Objects and arrays → JSON; strings → text; bytes → binary |

## Response headers Wisp adds

| Header | Meaning |
| --- | --- |
| `x-wisp-mode` | `test` or `live` |
| `x-wisp-version` | The version that answered |
| `x-wisp-duration-ms` | How long your code ran |
| `x-wisp-cache` | Edge cache status for cached functions |
| `ratelimit-*`, `retry-after` | When [rate limits](/rate-limits) apply |

CORS headers are added to every response, and `OPTIONS` preflight requests are answered for you.
