PHP code example of sinemacula / http-primitives-php

1. Go to this page and download the library: Download sinemacula/http-primitives-php 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/ */

    

sinemacula / http-primitives-php example snippets


use SineMacula\Http\Enums\Charset;
use SineMacula\Http\Enums\HttpStatus;
use SineMacula\Http\Enums\HttpMethod;
use SineMacula\Http\Enums\MediaType;

// Status code helpers
$status = HttpStatus::from(404);
$status->getCode();          // 404
$status->getStatusLine();    // '404 Not Found'
$status->isClientError();    // true
$status->getReasonPhrase();  // 'Not Found'

// Method safety checks
HttpMethod::GET->isSafe();        // true
HttpMethod::POST->isIdempotent(); // false

// Media type inspection
MediaType::APPLICATION_JSON->isApplication(); // true
MediaType::APPLICATION_JSON->getExtension();  // 'json'

// Content type composition
MediaType::TEXT_CSV->withCharset(Charset::UTF_8); // 'text/csv; charset=utf-8'