Skip to content

HttpMethod

Raxos\Http\HttpMethod

A backed string enum of the HTTP verbs used throughout the router and client.

php
enum HttpMethod: string

Cases

CaseValue
ANYANY
DELETEDELETE
GETGET
HEADHEAD
OPTIONSOPTIONS
PATCHPATCH
POSTPOST
PUTPUT

The ANY case is a wildcard used by the router to match every verb; it is not a real HTTP method.

Example

php
<?php
declare(strict_types=1);

use Raxos\Http\HttpMethod;

$method = HttpMethod::from('GET');

if ($method === HttpMethod::GET) {
    // handle a read request
}

Because HttpRequest::createFromGlobals() resolves the method for you, the enum usually arrives ready to compare:

php
use Raxos\Http\HttpRequest;

$request = HttpRequest::createFromGlobals();

if ($request->method === HttpMethod::POST) {
    $payload = $request->json();
}