ApiRequest
class ApiRequest extends Request
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected array | $data | The decoded payload for the request. |
from Request |
| protected bool | $hasDecodedData | Determine whether the request data has been decoded. |
from Request |
| protected array | $attributes | The attribute data passed when building the PendingRequest. |
from Request |
| protected array<string, mixed> | $context | from HasContext |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Determine if the request has a given header.
Determine if the request contains the given file.
Remove query parameters from the request.
Get the underlying PSR compliant request instance.
Set the API request/response context.
Get the API request/response context.
Set the request method.
Set the request URL.
Add the request header.
Add the request headers.
Specify the request's content type.
Indicate the request contains form parameters.
Indicate the request contains JSON.
Indicate that JSON should be returned by the server.
Indicate the type of content that should be returned by the server.
Specify an authorization token for the request.
Specify the user agent for the request.
Add a request header.
Add request headers.
Remove a request header.
Remove request headers.
Set the request body.
Merge the request data.
Remove keys from the request data.
Apply changed structured data to the request body.
Ensure structured data may be changed for the request.
Ensure the request body has a supported structured representation.
Replace the request body and update its framing headers.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
Request at line 41
__construct(RequestInterface $request)
Create a new request instance.
in
Request at line 48
string
method()
Get the request method.
in
Request at line 56
string
url()
Get the URL of the request.
in
Request at line 72
bool
hasHeader(string $key, mixed $value = null)
Determine if the request has a given header.
in
Request at line 90
bool
hasHeaders(array|string $headers)
Determine if the request has the given headers.
in
Request at line 102
array
header(string $key)
Get the values for the header with the given name.
in
Request at line 110
array
headers()
Get the request headers.
in
Request at line 118
string
body()
Get the body of the request.
in
Request at line 126
bool
hasFile(string $name, string|null $value = null, string|null $filename = null)
Determine if the request contains the given file.
in
Request at line 164
array
data()
Get the request's data (form parameters or JSON).
in
Request at line 179
protected array
parameters()
Get the request's form parameters.
in
Request at line 197
protected array
json()
Get the decoded JSON body of the request.
in
Request at line 224
bool
isForm()
Determine if the request is simple form data.
in
Request at line 232
bool
isJson()
Determine if the request is JSON.
in
Request at line 240
bool
isMultipart()
Determine if the request is multipart.
in
Request at line 248
protected string
mediaType()
Get the normalized request media type.
at line 220
Request
withData(array $data)
Replace the request data.
in
Request at line 274
array
query()
Get the request query parameters.
in
Request at line 300
Request
withoutQuery(array|string $keys = [])
Remove query parameters from the request.
in
Request at line 314
array
attributes()
Get the attribute data from the request.
in
Request at line 324
Request
setRequestAttributes(array $attributes)
Set the request's attribute data.
at line 268
RequestInterface
toPsrRequest()
Get the underlying PSR compliant request instance.
in
Request at line 344
bool
offsetExists(string $offset)
Determine if the given offset exists.
in
Request at line 354
mixed
offsetGet(string $offset)
Get the value for a given offset.
in
Request at line 366
void
offsetSet(string $offset, mixed $value)
Set the value at the given offset.
in
Request at line 378
void
offsetUnset(string $offset)
Unset the value at the given offset.
in
Request at line 386
static void
flushState()
Flush all static state.
in
HasContext at line 19
HasContext
withContext(array|string $key, mixed $value = null)
Set the API request/response context.
in
HasContext at line 35
mixed
context(string|null $key = null, mixed $default = null)
Get the API request/response context.
at line 24
static ApiRequest
createFrom(Request $request)
Create an API request from an HTTP client request.
at line 37
ApiRequest
withMethod(string $method)
Set the request method.
at line 47
ApiRequest
withUrl(callable|string $url, bool $preserveHost = false)
Set the request URL.
at line 61
ApiRequest
withHeader(string $key, array|string $value)
Add the request header.
at line 69
ApiRequest
withHeaders(array $headers)
Add the request headers.
at line 81
ApiRequest
contentType(string $contentType)
Specify the request's content type.
at line 94
ApiRequest
asForm()
Indicate the request contains form parameters.
at line 115
ApiRequest
asJson()
Indicate the request contains JSON.
at line 133
ApiRequest
acceptJson()
Indicate that JSON should be returned by the server.
at line 141
ApiRequest
accept(string $contentType)
Indicate the type of content that should be returned by the server.
at line 149
ApiRequest
withToken(string $token, string $type = 'Bearer')
Specify an authorization token for the request.
at line 157
ApiRequest
withUserAgent(bool|string $userAgent)
Specify the user agent for the request.
at line 165
ApiRequest
withAddedHeader(string $key, array|string $value)
Add a request header.
at line 173
ApiRequest
withAddedHeaders(array $headers)
Add request headers.
at line 185
ApiRequest
withoutHeader(string $header)
Remove a request header.
at line 193
ApiRequest
withoutHeaders(array $headers)
Remove request headers.
at line 205
ApiRequest
withBody(string $body)
Set the request body.
at line 237
ApiRequest
mergeData(array $data)
Merge the request data.
at line 254
ApiRequest
withoutData(array|string $keys)
Remove keys from the request data.
at line 278
protected void
applyChangedData()
Apply changed structured data to the request body.
at line 298
protected void
ensureStructuredMutationAllowed()
Ensure structured data may be changed for the request.
at line 314
protected void
ensureStructuredBody()
Ensure the request body has a supported structured representation.
at line 328
protected void
replaceBody(string $body)
Replace the request body and update its framing headers.