The method attribute is used to bind HTTP request methods to a corresponding route. The supported methods are only those documented in https://httpwg.org/specs/rfc9110.html#methods
#[Method(HttpMethod $method)]
method
requires the enumHttpMethod
which allowsGET
,HEAD
,POST
,PUT
,DELETE
,CONNECT
,OPTIONS
,TRACE
andPATCH
methods.
Attribute::TARGET_METHOD
Code:
#[Method(HttpMethod::GET)]
#[Path('/method')]
public function preflightExample(): ResponseBuilder
{
return (new ResponseBuilder())
->setHttpStatusCode(HttpStatusCode::HTTP_OK);
}
cURL:
curl --request GET \
--location 'http://localhost/method'