Menu
Reference
Method
enum Method: string
The nine HTTP methods defined by RFC 9110, as a typed view of the request method token.
Request::$method stays a raw string: methods outside this list (PROPFIND, PURGE) are legal
and have no case here. Use Request::methodEnum() for an exhaustive match, or
Request::is(Method::Post) for a single test.
Example
// Http\Status constants and helpers, Http\Method cases and predicates.
use Http\{Method, Status};
echo Status::NOT_FOUND, ' ', Status::text(Status::NOT_FOUND), "\n";
echo Status::text(299) === '' ? "299 has no phrase\n" : "unexpected\n";
foreach ([200, 204, 301, 304, 404] as $code) {
echo $code, ': redirect=', var_export(Status::isRedirect($code), true),
' body=', var_export(Status::hasBody($code), true), "\n";
}
foreach (Method::cases() as $m) {
echo str_pad($m->value, 8),
'safe=', var_export($m->isSafe(), true),
' idempotent=', var_export($m->isIdempotent(), true),
' body=', var_export($m->allowsBody(), true), "\n";
}
var_dump(Method::tryFrom('PROPFIND'));Output
404 Not Found
299 has no phrase
200: redirect=false body=true
204: redirect=false body=false
301: redirect=true body=true
304: redirect=false body=false
404: redirect=false body=true
GET safe=true idempotent=true body=false
HEAD safe=true idempotent=true body=false
POST safe=false idempotent=false body=true
PUT safe=false idempotent=true body=true
PATCH safe=false idempotent=false body=true
DELETE safe=false idempotent=true body=false
OPTIONS safe=true idempotent=true body=false
TRACE safe=true idempotent=true body=false
CONNECT safe=false idempotent=false body=false
NULLSee also: Request
Cases
Get | 'GET' | GET: retrieve a representation of the resource. |
Head | 'HEAD' | HEAD: like GET, headers only. |
Post | 'POST' | POST: submit data for processing. |
Put | 'PUT' | PUT: replace the resource. |
Patch | 'PATCH' | PATCH: partially modify the resource. |
Delete | 'DELETE' | DELETE: remove the resource. |
Options | 'OPTIONS' | OPTIONS: ask what the resource supports. |
Trace | 'TRACE' | TRACE: echo the request back for diagnosis. |
Connect | 'CONNECT' | CONNECT: open a tunnel (the server answers 501). |
Methods
isSafe() | No side effects expected of the origin (§9.2.1). |
isIdempotent() | Repeating it must read the same as doing it once (§9.2.2). |
allowsBody() | Whether a REQUEST body is meaningful. |
isSafe()#source
function isSafe(): bool
No side effects expected of the origin (§9.2.1).
Returns
bool — true for GET, HEAD, OPTIONS and TRACE.
isIdempotent()#source
function isIdempotent(): bool
Repeating it must read the same as doing it once (§9.2.2).
Returns
bool — true for the safe methods plus PUT and DELETE.
allowsBody()#source
function allowsBody(): bool
Whether a REQUEST body is meaningful. Not the same as "may carry one": a GET with a body is legal on the wire and forbidden to mean anything, so the framing rules read this to decide whether a missing Content-Length is a 411 or simply an empty request.
Returns
bool — true for POST, PUT and PATCH.