isize1ce / apiate
Lightweight HTTP microframework
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.1.3
- symfony/http-foundation: ^4.1
- symfony/yaml: ^4.1
README
Example
Request Handlers
ClosureHandler
new ClosureHandler(function(Request $request) { return new Response(); }));
ControllerHandler
class Controller { public function methodName(Request $request) { return new Response('Hello World!'); } } new ClosureHandler(Controller::class, 'methodName');
RouteHandler
class MyRequestHandler implements RouteRequestHandler { public function __construct(Request $request) { $this->text = $request->request->get('text', 'empty'); } public function handle() { return new Response('Hello World!'); } } new ClosureHandler(RouteController::class);
Namespaces
$routeProvider->namespace('/path', function(RequestProvider $pathRoutes) { $pathRoutes->get('/', SomeHandler); $pathRoutes->post('/', SomeHandler); $routeProvider->namespace('/anotherPath', function(RequestProvider $pathRoutes) { $pathRoutes->put('/', SomeHandler); $pathRoutes->delete('/', SomeHandler); } }));
Path regex
$routeProvider->get('/api/{uriParameterNameWithRegex=\d+}/{randomUriParameterWithoutRegex}', SomeHandler);