Search by

marko / routing

markshust

Marko Framework Routing

Package info

github.com/marko-php/marko-routing

pkg:composer/marko/routing

Statistics

Installs: 1 934

Dependents: 33

Suggesters: 0

Stars: 0

0.11.0 2026-10-06 15:08 UTC

README

Attribute-based routing with automatic conflict detection---define routes on controller methods, not in separate files.

Installation

composer require marko/routing

Quick Example

use Marko\Routing\Attributes\Get;
use Marko\Routing\Attributes\Post;
use Marko\Routing\Attributes\RoutePrefix;
use Marko\Routing\Exceptions\HttpException;
use Marko\Routing\Http\Response;

#[RoutePrefix('/shop', namePrefix: 'shop.')]
class ProductController
{
    #[Get('/products', name: 'products.index')]
    public function index(): Response
    {
        return new Response('Product list');
    }

    #[Get('/products/{id:\d+}', name: 'products.show')] // $urlGenerator->route('shop.products.show', ['id' => 7])
    public function show(int $id): Response
    {
        if ($id > 1000) {
            throw HttpException::notFound('Product not found.'); // 404, JSON or HTML
        }

        return new Response("Product $id");
    }

    #[Post('/products')]
    public function store(): Response
    {
        return new Response('Created', 201);
    }
}

Documentation

Full usage, API reference, and examples: marko/routing