---
sidebar:
  label: roboto.http.request
  order: 4
title: roboto.http.request
---
## Module Contents

### ALWAYS_SCRUBBED_HEADERS

```python
roboto.http.request.ALWAYS_SCRUBBED_HEADERS
```

`from roboto.http.request import ALWAYS_SCRUBBED_HEADERS`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L24-L24)

Header names, in lowercase, whose values `HttpRequest.describe` always replaces with `*`.

### BatchRequest

```python
class roboto.http.request.BatchRequest(/, **data: Any)
```

`from roboto import BatchRequest`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L180-L187)

Bases: `pydantic.BaseModel`, `Generic[Model]`

Request body for a route that applies several requests of one kind in one call.

Sent by [`import_batch()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.import_batch) to `POST /v1/files/import/batch`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **BatchRequest.requests** (`list[Model]`): Requests in the batch.

### HttpRequest

```python
class roboto.http.request.HttpRequest(
    url: str,
    method: str = 'GET',
    headers: Optional[dict[str, str]] = None,
    data: Any = None,
    retry_wait: Optional[roboto.http.retry.RetryWaitFn] = None,
    idempotent: bool = False,
)
```

`from roboto.http import HttpRequest`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L28-L170)

An HTTP request for [`HttpClient`](/docs/reference/python-sdk/roboto/http/http_client#roboto.http.http_client.HttpClient) to send, with the settings that govern its retries.

[`HttpClient`](/docs/reference/python-sdk/roboto/http/http_client#roboto.http.http_client.HttpClient) builds one for each call it makes, and passes it to its authentication decorator and to its retry predicate. Its constructor takes one parameter for each attribute, of the same name.

**Parameters**

- **url** (`str`)
- **method** (`str`)
- **headers** (`Optional[dict[str, str]]`)
- **data** (`Any`)
- **retry_wait** (`Optional[roboto.http.retry.RetryWaitFn]`)
- **idempotent** (`bool`)

**Attributes**

- **HttpRequest.data** (`Any`) = `None`: Request body, or `None` for no body.

  A pydantic model or a dictionary also sets the `Content-Type` header to `application/json`. `body` says how each type is encoded.

- **HttpRequest.headers** (`dict`): Headers to send with the request.

  The request adds to the dictionary passed to its constructor in place, not to a copy. Passing `None` starts with no headers.

- **HttpRequest.idempotent** (`bool`) = `False`: Whether sending the request more than once has the same effect as sending it once.

  The default retry predicate, [`is_expected_to_be_transient()`](/docs/reference/python-sdk/roboto/http/http_client#roboto.http.http_client.is_expected_to_be_transient), retries connection errors, timeouts, and responses with status 408, 500 or 504 only for an idempotent request.

- **HttpRequest.method** (`str`): HTTP method, such as `"GET"` or `"POST"`.

- **HttpRequest.retry_wait** (`roboto.http.retry.RetryWaitFn`): Function that returns how long to wait before the next attempt, in milliseconds.

  It takes the `tenacity.RetryCallState` of the request and an exception, which [`HttpClient`](/docs/reference/python-sdk/roboto/http/http_client#roboto.http.http_client.HttpClient) always passes as `None`. Passing `None` to the constructor waits a random time of up to 1 second after the first attempt, doubling that limit after each attempt up to 30 seconds.

- **HttpRequest.url** (`str`): Absolute URL to send the request to.

**Properties**

- **HttpRequest.body** (`bytes | None`): Request body as the bytes sent, or `None` when the request has no body.

  Each type of `data` is encoded as follows:

  - `bytes` is sent as given.
  - A string is encoded as UTF-8.
  - A pydantic model is encoded as JSON, leaving out the fields the caller never set.
  - Anything else is encoded as JSON by `json.dumps`.

  Reading it raises `TypeError` when `data` is of a type `json.dumps` cannot encode.

  Return type: `Optional[bytes]`

- **HttpRequest.hostname** (`str`): Host name in the request's URL, without the port.

  The URL's whole network location when no host name can be parsed from it.

- **HttpRequest.origin** (`str`): Scheme, host and port of the request's URL, such as `https://hooks.slack.com`.

  Any user name or password the URL carries is left out.

#### HttpRequest.append_headers()

```python
def append_headers(headers: dict[str, str]) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L164-L170)

Add headers to the request, replacing the value of any header with the same name, matched case-sensitively.

**Parameters**

- **headers** (`dict[str, str]`): Headers to add.

**Returns**

- `None`

#### HttpRequest.describe()

```python
def describe(
    scrub_headers: Collection[str] = (),
    only_method_and_origin: bool = False,
) -> str
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L92-L116)

Render the request for logging, with sensitive header values replaced by `*`.

Unless `only_method_and_origin` is `True`, the body is rendered in full; nothing in it is scrubbed.

**Parameters**

- **scrub_headers** (`Collection[str]`): Header names, compared case-insensitively, whose values to replace in addition to `ALWAYS_SCRUBBED_HEADERS`.
- **only_method_and_origin** (`bool`): Whether to render only the method and the URL's `origin`, leaving out the URL's path and query, the headers, and the body.

**Returns**

- `str`

### HttpRequestDecorator

```python
roboto.http.request.HttpRequestDecorator
```

`from roboto.http.request import HttpRequestDecorator`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L173-L173)

Function that prepares a request before it is sent, such as by adding authentication headers, and returns it.

[`BearerTokenDecorator`](/docs/reference/python-sdk/roboto/http/request_decorators#roboto.http.request_decorators.BearerTokenDecorator) and [`SigV4AuthDecorator`](/docs/reference/python-sdk/roboto/http/request_decorators#roboto.http.request_decorators.SigV4AuthDecorator) are two.

### Model

```python
roboto.http.request.Model
```

`from roboto.http.request import Model`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/request.py#L21-L21)

Type of the requests a `BatchRequest` holds.
