programster/http-codes

A package to make HTTP status codes easier.

2.0.0 2021-12-18 10:28 UTC

This package is auto-updated.

Last update: 2024-10-18 16:28:52 UTC


README

This is a PHP package providing an enum for the various HTTP response codes as found on Wikipedia.

Install

composer require programster/http-codes

Example Usage

Below is an example of using the package to return a 404 JSON response for an API request.

<?php
use Programster\Http\HttpCode;

http_response_code(HttpCode::NOT_FOUND);

$body = [
    "result" => "error",
    "message" => "Resource not found.",
];

header('Content-Type: application/json');
die(json_encode($body));