marcoazn89 / http-wrapper
An HTTP wraper library
Installs: 27 769
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is not auto-updated.
Last update: 2025-05-10 21:25:01 UTC
README
composer require marcoazn89/http-wrapper:dev-dev
Features
- PSR-7 compliant response object
- Content negotiation
- Constants to avoid mistyping
- Flexibility to use outside of PSR-7
Create a new response object
require '../vendor/autoload.php'; $response = new \HTTP\Response();
Set headers
require '../vendor/autoload.php'; (new \HTTP\Response())->withType(\HTTP\Response\ContentType::JSON) ->write(['greeting' => 'Hello World'])->send();
Negotiate Headers
require '../vendor/autoload.php'; //Assuming the client send Accept:text/plain (new \HTTP\Response())->withTypeNegotiation()->write("Test")->send();
Set limits on what you can support
The order in which you add support matters! This will ignore any Accept headers that don't match the supported types.
require '../vendor/autoload.php'; use HTTP\Support\TypeSupport; use HTTP\Response\ContentType; // Add content you can support TypeSupport::addSupport([ ContentType::HTML, ContentType::XML ]); // Assume the client sent XML as the accept header, the following output will be // in XML form because it was the best match in the supported types (new \HTTP\Response())->withTypeNegotiation()->write("<p>Hello World</p>")->send();