laylatichy\nano\core\response\Response
useResponse(): Response
useResponse
(): Response
php
useRouter()->get('/', fn (): Response => useResponse());
// generate response with code 200, empty body and no headers
getCode(): HttpCode
getCode
(): HttpCode
php
useResponse()->getCode(); // HttpCode::OK
withCode(HttpCode $code): Response
withCode
(HttpCode $code
): Response
set response code
php
useRouter()->get('/', fn (): Response => useResponse()
->withCode(HttpCode::NOT_FOUND));
getHeaders(): array
getHeaders
(): array
php
useResponse()->getHeaders(); // []
withHeader(string $key, string $value): Response
withHeader
(string $key,
string $value
): Response
set response header
php
useRouter()->get('/', fn (): Response => useResponse()
->withHeader('Content-Type', 'application/json'));
getBody(): string
getBody
(): string
php
useResponse()->getBody(); // ''
withText(string $body): Response
withText
(string $body
): Response
set response body as text
php
useRouter()->get('/', fn (): Response => useResponse()
->withText('Hello, World!'));
withJson(array $body): Response
withJson
(array $body
): Response
set response body as json
php
useRouter()->get('/', fn (): Response => useResponse()
->withJson(['message' => 'Hello, World!']));
useStatusResponse(): Response
useStatusResponse
(): Response
generate server status response
php
useRouter()->get('/', fn (): Response => useStatusResponse());
useNotFoundResponse(): Response
useNotFoundResponse
(): Response
generate not found response
php
useRouter()->get('/', fn (): Response => useNotFoundResponse());