composer require kmvan/response
- PHP 8.1 or later
<?php
use Kmvan\Response;
$res = new Response();
// 404 not found
$res->setStatus(404)
->end(); // exit
// 201 created
$res->setStatus(201)
->setData([ // output json
'name' => 'Jack',
])
->end(); // exit
Good experience with composer require kmvan/status-code
library.
<?php
use Kmvan\StatusCode;
use Kmvan\Response;
$req = new Response();
$req->setStatus(StatusCode::OK) // http status code 200
->end();