paliari / nano-http
nano http
0.0.2
2020-05-02 21:58 UTC
Requires
- ext-json: *
- paliari/php-utils: ^1.1
This package is auto-updated.
Last update: 2024-12-29 07:03:46 UTC
README
The fastest http php framework
How to Install
composer require paliari/nano-http
Usage
<?php require 'vendor/autoload.php';
Routing
HTTP method: GET, POST, PUT, PATCH, DELETE
Mapping
//... $app = new \Paliari\NanoHttp\App(); $app->get('/', function ($req, \Paliari\NanoHttp\Http\Response $res) { $res->body = json_encode(['message' => 'Welcome']); return $res; }); $app->post('/person', function ($req, \Paliari\NanoHttp\Http\Response $res) { $params = $req->post(); $person = yourMethodCreatePerson($params); $res->body = json_encode($person); return $res; }); $app->get('/person/{id}', function ($req, \Paliari\NanoHttp\Http\Response $res, $id) { $person = yourMethodGetPerson($id); $res->body = json_encode($person); return $res; });
Custom map
App->map(method: string, route: string, callable: string|callable) if the callable is string it must be separated by ":" eg: "ClassName:metodName".
$app->map($method, $route, $callable);
Middleware
Using MiddlewareInterface
<?php class AuthMiddleware implements \Paliari\NanoHttp\Middleware\MiddlewareInterface { public function __invoke($request, $response, $next) { // TODO: Implement __invoke() method. // ... return $response; } }
<?php //... $authMiddleware = new AuthMiddleware(); $aclMiddleware = new AclMiddleware(); $customMiddleware = new CustomMiddleware(); $app->add($customMiddleware, '/custom/path') ->add($aclMiddleware, '/') ->add($authMiddleware, '/') ;