OhHttp is a HTTP Request and Response library for PHP
To use OhHttp with Composer, add the dependency (and version constraint) to your require block inside your composer.json
file.
{
"require": {
"rogerthomas84/ohhttp": "1.0.*"
}
}
You can use the \OhHttp\Request
and \OhHttp\Response
to provide a simplified HTTP Request and Response, but moving
towards a more OO approach.
$request = new \OhHttp\Request();
if ($request->isGet()) {
$userId = $request->getParam('id', null);
// do something
} elseif ($request->isPost()) {
$userId = $request->getParam('id', null);
// do something
}
$response = new \OhHttp\Response();
$response->setHeader('Content-Type', 'application/json');
$response->setBody('{"foo":"bar"}');
$response->send();