W3cubDocs

/Laravel 8

PendingRequest

class PendingRequest (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
protected Factory|null $factory The factory instance.
protected string $baseUrl The base URL for the request.
protected string $bodyFormat The request body format.
protected string $pendingBody The raw body for the request.
protected array $pendingFiles The pending files for the request.
protected array $cookies The request cookies.
protected $transferStats The transfer stats for the request.
protected array $options The request options.
protected int $tries The number of times to try the request.
protected int $retryDelay The number of milliseconds to wait between retries.
protected array $beforeSendingCallbacks The callbacks that should execute before the request is sent.
protected Collection|null $stubCallbacks The stub callables that will handle requests.
protected Collection $middleware The middleware callables added by users that will handle requests.

Methods

static void macro(string $name, object|callable $macro)

Register a custom macro.

from Macroable
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
void __construct(Factory $factory = null)

Create a new HTTP Client instance.

$this baseUrl(string $url)

Set the base URL for the pending request.

$this withBody(resource|string $content, string $contentType)

Attach a raw body to the request.

$this asJson()

Indicate the request contains JSON.

$this asForm()

Indicate the request contains form parameters.

$this attach(string|array $name, string $contents = '', string|null $filename = null, array $headers = [])

Attach a file to the request.

$this asMultipart()

Indicate the request is a multi-part form request.

$this bodyFormat(string $format)

Specify the body format of the request.

$this contentType(string $contentType)

Specify the request's content type.

$this acceptJson()

Indicate that JSON should be returned by the server.

$this accept(string $contentType)

Indicate the type of content that should be returned by the server.

$this withHeaders(array $headers)

Add the given headers to the request.

$this withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

$this withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

$this withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

$this withUserAgent(string $userAgent)

Specify the user agent for the request.

$this withCookies(array $cookies, string $domain)

Specify the cookies that should be included with the request.

$this withoutRedirecting()

Indicate that redirects should not be followed.

$this withoutVerifying()

Indicate that TLS certificates should not be verified.

$this sink(string|resource $to)

Specify the path where the body of the response should be stored.

$this timeout(int $seconds)

Specify the timeout (in seconds) for the request.

$this retry(int $times, int $sleep = 0)

Specify the number of times the request should be attempted.

$this withOptions(array $options)

Merge new options into the client.

$this withMiddleware(callable $middleware)

Add new middleware the client handler stack.

$this beforeSending(callable $callback)

Add a new "before sending" callback to the request.

Response get(string $url, array|string|null $query = null)

Issue a GET request to the given URL.

Response head(string $url, array|string|null $query = null)

Issue a HEAD request to the given URL.

Response post(string $url, array $data = [])

Issue a POST request to the given URL.

Response patch(string $url, array $data = [])

Issue a PATCH request to the given URL.

Response put(string $url, array $data = [])

Issue a PUT request to the given URL.

Response delete(string $url, array $data = [])

Issue a DELETE request to the given URL.

Response send(string $method, string $url, array $options = [])

Send the request to the given URL.

array|array[] parseMultipartBodyFormat(array $data)

Parse multi-part form data.

array parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

Client buildClient()

Build the Guzzle client.

HandlerStack buildHandlerStack()

Build the before sending handler stack.

Closure buildBeforeSendingHandler()

Build the before sending handler.

Closure buildRecorderHandler()

Build the recorder handler.

Closure buildStubHandler()

Build the stub handler.

Closure sinkStubHandler(string $sink)

Get the sink stub handler callback.

Closure runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

array mergeOptions(array ...$options)

Merge the given options with the current request options.

$this stub(callable $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(Factory $factory = null)

Create a new HTTP Client instance.

Parameters

Factory $factory

Return Value

void

$this baseUrl(string $url)

Set the base URL for the pending request.

Parameters

string $url

Return Value

$this

$this withBody(resource|string $content, string $contentType)

Attach a raw body to the request.

Parameters

resource|string $content
string $contentType

Return Value

$this

$this asJson()

Indicate the request contains JSON.

Return Value

$this

$this asForm()

Indicate the request contains form parameters.

Return Value

$this

$this attach(string|array $name, string $contents = '', string|null $filename = null, array $headers = [])

Attach a file to the request.

Parameters

string|array $name
string $contents
string|null $filename
array $headers

Return Value

$this

$this asMultipart()

Indicate the request is a multi-part form request.

Return Value

$this

$this bodyFormat(string $format)

Specify the body format of the request.

Parameters

string $format

Return Value

$this

$this contentType(string $contentType)

Specify the request's content type.

Parameters

string $contentType

Return Value

$this

$this acceptJson()

Indicate that JSON should be returned by the server.

Return Value

$this

$this accept(string $contentType)

Indicate the type of content that should be returned by the server.

Parameters

string $contentType

Return Value

$this

$this withHeaders(array $headers)

Add the given headers to the request.

Parameters

array $headers

Return Value

$this

$this withBasicAuth(string $username, string $password)

Specify the basic authentication username and password for the request.

Parameters

string $username
string $password

Return Value

$this

$this withDigestAuth(string $username, string $password)

Specify the digest authentication username and password for the request.

Parameters

string $username
string $password

Return Value

$this

$this withToken(string $token, string $type = 'Bearer')

Specify an authorization token for the request.

Parameters

string $token
string $type

Return Value

$this

$this withUserAgent(string $userAgent)

Specify the user agent for the request.

Parameters

string $userAgent

Return Value

$this

$this withCookies(array $cookies, string $domain)

Specify the cookies that should be included with the request.

Parameters

array $cookies
string $domain

Return Value

$this

$this withoutRedirecting()

Indicate that redirects should not be followed.

Return Value

$this

$this withoutVerifying()

Indicate that TLS certificates should not be verified.

Return Value

$this

$this sink(string|resource $to)

Specify the path where the body of the response should be stored.

Parameters

string|resource $to

Return Value

$this

$this timeout(int $seconds)

Specify the timeout (in seconds) for the request.

Parameters

int $seconds

Return Value

$this

$this retry(int $times, int $sleep = 0)

Specify the number of times the request should be attempted.

Parameters

int $times
int $sleep

Return Value

$this

$this withOptions(array $options)

Merge new options into the client.

Parameters

array $options

Return Value

$this

$this withMiddleware(callable $middleware)

Add new middleware the client handler stack.

Parameters

callable $middleware

Return Value

$this

$this beforeSending(callable $callback)

Add a new "before sending" callback to the request.

Parameters

callable $callback

Return Value

$this

Response get(string $url, array|string|null $query = null)

Issue a GET request to the given URL.

Parameters

string $url
array|string|null $query

Return Value

Response

Response head(string $url, array|string|null $query = null)

Issue a HEAD request to the given URL.

Parameters

string $url
array|string|null $query

Return Value

Response

Response post(string $url, array $data = [])

Issue a POST request to the given URL.

Parameters

string $url
array $data

Return Value

Response

Response patch(string $url, array $data = [])

Issue a PATCH request to the given URL.

Parameters

string $url
array $data

Return Value

Response

Response put(string $url, array $data = [])

Issue a PUT request to the given URL.

Parameters

string $url
array $data

Return Value

Response

Response delete(string $url, array $data = [])

Issue a DELETE request to the given URL.

Parameters

string $url
array $data

Return Value

Response

Response send(string $method, string $url, array $options = [])

Send the request to the given URL.

Parameters

string $method
string $url
array $options

Return Value

Response

Exceptions

Exception

protected array|array[] parseMultipartBodyFormat(array $data)

Parse multi-part form data.

Parameters

array $data

Return Value

array|array[]

protected array parseRequestData(string $method, string $url, array $options)

Get the request data as an array so that we can attach it to the request for convenient assertions.

Parameters

string $method
string $url
array $options

Return Value

array

Client buildClient()

Build the Guzzle client.

Return Value

Client

HandlerStack buildHandlerStack()

Build the before sending handler stack.

Return Value

HandlerStack

Closure buildBeforeSendingHandler()

Build the before sending handler.

Return Value

Closure

Closure buildRecorderHandler()

Build the recorder handler.

Return Value

Closure

Closure buildStubHandler()

Build the stub handler.

Return Value

Closure

protected Closure sinkStubHandler(string $sink)

Get the sink stub handler callback.

Parameters

string $sink

Return Value

Closure

Closure runBeforeSendingCallbacks(RequestInterface $request, array $options)

Execute the "before sending" callbacks.

Parameters

RequestInterface $request
array $options

Return Value

Closure

array mergeOptions(array ...$options)

Merge the given options with the current request options.

Parameters

array ...$options

Return Value

array

$this stub(callable $callback)

Register a stub callable that will intercept requests and be able to return stub responses.

Parameters

callable $callback

Return Value

$this

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Http/Client/PendingRequest.html