klorinmannen/projom-http

Projom http module

v1.0.1 2025-03-29 10:26 UTC

This package is auto-updated.

Last update: 2025-06-30 07:36:08 UTC


README

PHP version support PHPUnit

Project goals

  • Routing requests
  • Support a selective scope of OAS 3.0.

Docs

Visit the repository wiki pages.

Example usage

use Projom\Http\Request;
use Projom\Http\Route\RouteInterface;

use Recipe\Auth\PreflightMiddleware;
use Recipe\Controller as RecipeController;
use Recipe\Ingredient\Controller as RecipeIngredientController;

$router = new Router();

$router->addRoute('/', 
	RecipeController::class, 
	function (RouteInterface $route) {
		$route->get();
	}
);

$router->addRoute(
	'/recipes', 
	RecipeController::class, 
	function (RouteInterface $route) {
		
		$route->get()
			->optionalQueryParameters(['sort' => 'string'])
			->expectsQueryParameters(['page' => 'integer']);
		
		$route->post()->expectsPayload();
	}
);

$router->addRoute(
	'/recipes/{numeric_id:recipe_id}',
	RecipeController::class, 
	function (RouteInterface $route) {
		$route->get('getRecipe');
		$route->patch('updateRecipe')->expectsPayload();
	}
);

$router->addRoute(
	'/recipes/{numeric_id:recipe_id}/ingredients',
	RecipeIngredientController::class, 
	function (RouteInterface $route) {
		
		$route->get()
			->optionalQueryParameters(['sort' => 'string'])
			->expectsQueryParameters(['page' => 'integer']);
		
		$route->post()->expectsPayload();
	}
);

$router->addRoute(
	'/recipes/{numeric_id:recipe_id}/ingredients/{numeric_id:ingredient_id}',
	RecipeIngredientController::class, 
	function (RouteInterface $route) {
		$route->get('getIngredient');
		$route->patch('updateIngredient')->expectsPayload();
	}
);

$router->addMiddleware(PreflightMiddleware::create());

$router->dispatch(Request::create());