-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
phpgt/http provides the low-level HTTP objects used throughout the PHP.GT ecosystem. It implements the core PSR-7 message interfaces, but it also adds a set of practical helpers around URIs, headers, form bodies, query strings, streams, and HTTP status handling.
If you are new to HTTP libraries in PHP, the important idea is simple: this package gives us PHP objects that represent the same pieces of web traffic the browser and the server already exchange all day long.
That means we can:
- build and inspect
RequestandServerRequestobjects - create and modify
Responseobjects - work with
Uriobjects instead of string slicing - manage headers in a case-insensitive, iterable way
- convert form and query-string data with browser-style helper objects
- wrap
$_SERVERmetadata in a predictable API - represent common HTTP errors as dedicated exception classes
composer require phpgt/httpIf you are working inside WebEngine, this package is already part of the normal request/response lifecycle.
Note
If you are building with WebEngine, you will not usually construct every object here by hand. WebEngine uses RequestFactory to build the incoming request, passes Request and Response objects through the application lifecycle, exposes ResponseHeaders as a service, and relies on the HTTP status exception classes when generating error responses.
use GT\Http\RequestFactory;
use GT\Http\Response;
$request = (new RequestFactory())
->createServerRequestFromGlobalState(
$_SERVER,
$_FILES,
$_GET,
$_POST
);
$response = new Response();
$response = $response
->withStatus(200)
->withHeader("Content-Type", "text/plain");
$response->getBody()->write("Hello, " . $request->getMethod());In practice, that means the incoming HTTP request is wrapped in an object you can pass around safely, and the outgoing response is built in the same way.
To see how the pieces fit together before diving into the individual classes, continue to the Overview.
PHP.GT/Http is a separately maintained component of PHP.GT/WebEngine.
- Creating requests from global state
- Request and ServerRequest objects
- Response objects
- URI objects
- Working with headers
- Parts of the HTTP header