klorinmannen / projom-http
Projom http module
v1.0.1
2025-03-29 10:26 UTC
Requires (Dev)
- phpunit/phpunit: ^11.0.0
README
Project goals
- Routing requests
- Dispatching requests
- Support a selective scope of OAS 3.0.
Docs
Visit the repository wiki pages.
Example usage
use Projom\Http\Router;
use Projom\Http\Router\RouteInterface;
use Projom\Http\Router\ParameterType;
use Recipe\Controller as RecipeController;
use Recipe\Ingredient\Controller as RecipeIngredientController;
$router = new Router();
$router->addRoute('/',
RootController::class,
function (RouteInterface $route) {
$route->get();
}
);
$router->addRoute(
'/recipes',
RecipeController::class,
function (RouteInterface $route) {
$route->get()
->optionalQueryParameters(['sort' => ParameterType::STR])
->requiredQueryParameters(['page' => ParameterType::INT,
'limit' => ParameterType::INT]);
$route->post()->requiredPayload();
}
);
$router->addRoute(
'/recipes/{numeric_id:recipe_id}',
RecipeController::class,
function (RouteInterface $route) {
$route->get('getRecipe');
$route->patch('patchRecipe')->requiredPayload();
}
);
$router->addRoute(
'/recipes/{numeric_id:recipe_id}/ingredients',
RecipeIngredientController::class,
function (RouteInterface $route) {
$route->get()
->optionalQueryParameters(['sort' => ParameterType::STR])
->requiredQueryParameters(['page' => ParameterType::INT,
'limit' => ParameterType::INT]);
$route->post()->requiredPayload();
}
);
$router->addRoute(
'/recipes/{numeric_id:recipe_id}/ingredients/{numeric_id:ingredient_id}',
RecipeIngredientController::class,
function (RouteInterface $route) {
$route->get('getIngredient');
$route->patch('patchIngredient')->requiredPayload();
}
);
$router->dispatch();