Title: Request::__construct
Published: May 20, 2026

---

# Request::__construct( WordPressAiClientProvidersHttpEnumsHttpMethodEnum $method, string $uri,  $headers = [],  $data = null, WordPressAiClientProvidersHttpDTORequestOptions|null $options = null )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#wp--skip-link--target)

Constructor.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#parameters)󠁿

 `$method`WordPressAiClientProvidersHttpEnumsHttpMethodEnumrequired

The HTTP method.

`$uri`stringrequired

The request URI.

mixed>|null $data The request data.

`$options`WordPressAiClientProvidersHttpDTORequestOptions|nulloptional

The request transport options.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct(HttpMethodEnum $method, string $uri, array $headers = [], $data = null, ?\WordPress\AiClient\Providers\Http\DTO\RequestOptions $options = null)
    {
        if (empty($uri)) {
            throw new InvalidArgumentException('URI cannot be empty.');
        }
        $this->method = $method;
        $this->uri = $uri;
        $this->headers = new HeadersCollection($headers);
        // Separate data and body based on type
        if (is_string($data)) {
            $this->body = $data;
        } elseif (is_array($data)) {
            $this->data = $data;
        }
        $this->options = $options;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/http/dto/request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php#L75)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php#L75-L90)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#related)󠁿

| Uses | Description | 
| [HeadersCollection::__construct()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-collections-headerscollection/__construct/)`wp-includes/php-ai-client/src/Providers/Http/Collections/HeadersCollection.php` |

Constructor.

  |

| Used by | Description | 
| [Request::fromPsrRequest()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/frompsrrequest/)`wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php` |

Creates a Request instance from a PSR-7 RequestInterface.

  | 
| [Request::fromArray()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/fromarray/)`wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php` |

{@inheritDoc}

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.1.0](https://developer.wordpress.org/reference/since/0.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-providers-http-dto-request%2F__construct%2F)
before being able to contribute a note or feedback.