# Trait HttpSoft\Message\RequestTrait

Trait implementing the methods defined in Psr\Http\Message\RequestInterface, used within HttpSoft\Message\Request and HttpSoft\Message\ServerRequest.

Source code on GitHub.

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\RequestInterface.

All other methods with descriptions are in the used trait (HttpSoft\Message\MessageTrait).

Setters prefixed with with they are immutable and return a new instance of the class (using HttpSoft\Message\RequestTrait) with the changed data.

# getRequestTarget

Returns the message's request target.

public function getRequestTarget(): string;

Example of returned values: '/', '*', 'path/to/target?query=string', 'user:pass@example.com:8080'.

# withRequestTarget

Returns a new instance with the specified request-target.

/**
 * @param mixed $requestTarget
 * @return static
 */
public function withRequestTarget($requestTarget): RequestInterface;

If invalid specified request-target, the \InvalidArgumentException exception will be thrown.

$request->getRequestTarget(); // '/'

$newRequest = $request->withRequestTarget('*');
$newRequest->getRequestTarget(); // '*'
$request->getRequestTarget(); // '/'

$request->withRequestTarget('/ *') // throws InvalidArgumentException

# getMethod

Returns the HTTP method of the request.

public function getMethod(): string;

Example of returned values: 'GET', 'HEAD', 'POST'.

# withMethod

Returns a new instance with the specified HTTP method of the request. The method name is case-sensitive.

/**
 * @param string $method
 * @return static
 */
public function withMethod($method): RequestInterface;

If invalid specified request method, the \InvalidArgumentException exception will be thrown.

$request->getMethod(); // 'GET'

$newRequest = $request->withMethod('POST');
$newRequest->getMethod(); // 'POST'
$request->getMethod(); // 'GET'

$request->withMethod(null); // throws InvalidArgumentException
$request->withMethod("GE\nT") // throws InvalidArgumentException

# getUri

Returns the Psr\Http\Message\UriInterface instance.

public function getUri(): UriInterface;

The HttpSoft\Message\Uri implements Psr\Http\Message\UriInterface.

# withUri

Returns a new instance with the specified Psr\Http\Message\UriInterface instance.

public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface;

If $preserveHost === true the previous host header will be preserved if it existed.