1. Go to this page and download the library: Download ctw/ctw-http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ctw / ctw-http example snippets
use Ctw\Http\HttpStatus;
$httpStatus = new HttpStatus(HttpStatus::STATUS_NOT_FOUND);
$entity = $httpStatus->get();
// Returns:
// Ctw\Http\Entity\HttpStatus {
// +statusCode: 404
// +name: "Not Found"
// +phrase: "The requested resource could not be found but may be available again in the future."
// +exception: "Ctw\Http\HttpException\NotFoundException"
// +url: "https://httpstatuses.com/404"
// }
use Ctw\Http\HttpException;
// Default message uses status name
throw new HttpException\NotFoundException();
// "404 Not Found"
// Custom message
throw new HttpException\NotFoundException('User with ID 123 not found');
// "User with ID 123 not found"
// With custom headers
throw new HttpException\UnauthorizedException(
message: 'Invalid API key',
headers: ['WWW-Authenticate' => 'Bearer']
);