Lightweight object-oriented HTTP foundation for PHP.

Installs: 20

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/codemonster-ru/http

v1.0.0 2025-10-23 14:51 UTC

This package is auto-updated.

Last update: 2025-10-23 14:53:07 UTC


README

Latest Version on Packagist Total Downloads License Tests

Lightweight object-oriented HTTP foundation for PHP.

๐Ÿ“ฆ Installation

composer require codemonster-ru/http

๐Ÿš€ Usage

Handling HTTP Requests

use Codemonster\Http\Request;

// Capture the current request from PHP globals
$request = Request::capture();

echo $request->method();      // GET
echo $request->uri();         // /hello
echo $request->query('id');   // 42
echo $request->input('name'); // Vasya

You can also create a request manually (useful for tests or CLI):

$request = new Request(
    'POST',
    '/api/user',
    ['page' => 2],
    ['name' => 'John'],
    ['Accept' => 'application/json']
);

if ($request->wantsJson()) {
    // Return JSON
}

Sending HTTP Responses

use Codemonster\Http\Response;

// Basic response
$response = new Response('Hello world', 200);
$response->send();

// JSON response
return Response::json(['ok' => true])->send();

// Redirect
return Response::redirect('/login');

// Custom headers
$response = (new Response('Created', 201))
    ->header('X-Custom', '1')
    ->type('text/plain')
    ->send();

๐Ÿงช Testing

You can run tests with the command:

composer test

๐Ÿ‘จโ€๐Ÿ’ป Author

Kirill Kolesnikov

๐Ÿ“œ License

MIT