codemonster-ru / http
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
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2025-10-23 14:53:07 UTC
README
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