Skip to content
laylatichy\nano\core\response\Response

useResponse
():
Response

php
useRouter()->get('/', fn (): Response => useResponse());

// generate response with code 200, empty body and no headers

getCode
():
HttpCode

php
useResponse()->getCode(); // HttpCode::OK

withCode
(
HttpCode $code
):
Response

set response code

php
useRouter()->get('/', fn (): Response => useResponse()
    ->withCode(HttpCode::NOT_FOUND));

getHeaders
():
array

php
useResponse()->getHeaders(); // []

withHeader
(
string $key
string $value
):
Response

set response header

php
useRouter()->get('/', fn (): Response => useResponse()
    ->withHeader('Content-Type', 'application/json'));

getBody
():
string

php
useResponse()->getBody(); // ''

withText
(
string $body
):
Response

set response body as text

php
useRouter()->get('/', fn (): Response => useResponse()
    ->withText('Hello, World!'));

withJson
(
array $body
):
Response

set response body as json

php
useRouter()->get('/', fn (): Response => useResponse()
    ->withJson(['message' => 'Hello, World!']));

useStatusResponse
():
Response

generate server status response

php
useRouter()->get('/', fn (): Response => useStatusResponse());

useNotFoundResponse
():
Response

generate not found response

php
useRouter()->get('/', fn (): Response => useNotFoundResponse());