All Projects → middlewares → fast-route

middlewares / fast-route

Licence: MIT license
PSR-15 middleware to use FastRoute

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to fast-route

Router
Router implementation for fasthttp
Stars: ✭ 234 (+157.14%)
Mutual labels:  router
rux
⚡ Rux is an simple and fast web framework. support route group, param route binding, middleware, compatible http.Handler interface. 简单且快速的 Go api/web 框架,支持路由分组,路由参数绑定,中间件,兼容 http.Handler 接口
Stars: ✭ 81 (-10.99%)
Mutual labels:  router
lura
Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
Stars: ✭ 5,159 (+5569.23%)
Mutual labels:  router
Clevergo
👅 CleverGo is a lightweight, feature rich and high performance HTTP router for Go.
Stars: ✭ 246 (+170.33%)
Mutual labels:  router
Cortex-Plugin
Cortex Plugin, a routing system for WordPress
Stars: ✭ 21 (-76.92%)
Mutual labels:  fastroute
FGRoute
Get your device ip address, router ip or wifi ssid
Stars: ✭ 128 (+40.66%)
Mutual labels:  router
Mu
A tweet-sized PHP micro-router
Stars: ✭ 229 (+151.65%)
Mutual labels:  router
easytcp
✨ 🚀 EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful.
Stars: ✭ 416 (+357.14%)
Mutual labels:  router
PHP-Frameworks-Bench
Popular PHP Frameworks Benchmark.
Stars: ✭ 28 (-69.23%)
Mutual labels:  fastroute
tulingx
TULINGX(图灵)VPN下载页 翻墙 代理 科学上网 外网 加速器 梯子 路由
Stars: ✭ 59 (-35.16%)
Mutual labels:  router
Golf
⛳️ The Golf web framework
Stars: ✭ 248 (+172.53%)
Mutual labels:  router
router-fastroute
Yii Router FastRoute adapter
Stars: ✭ 36 (-60.44%)
Mutual labels:  fastroute
dilovel
An advanced framework is written in PHP, a framework containing rich components such as middleware, orm, request management, template engine, elasticsearch, template engine, many modern frameworks have been written by adopting clean code principles completely written in accordance with PHP standards. like linux operating system ...All of control…
Stars: ✭ 38 (-58.24%)
Mutual labels:  router
Swiftuirouter
Routing in SwiftUI
Stars: ✭ 242 (+165.93%)
Mutual labels:  router
es6-router
🌐 Simple client side router built in ES6
Stars: ✭ 16 (-82.42%)
Mutual labels:  router
Klein.php
A fast & flexible router
Stars: ✭ 2,622 (+2781.32%)
Mutual labels:  router
svelte-micro
Light & reactive one-component router for Svelte
Stars: ✭ 81 (-10.99%)
Mutual labels:  router
journey
A conductor routing helper library
Stars: ✭ 35 (-61.54%)
Mutual labels:  router
RoundedLayout
This is a library that has a rounded cut of View, support whether the specified corners are cropped and add a custom Border, and add a shadow support from API 9, which is based on FrameLayout, that is, His Child can be any View, the current library or preview version, if you encounter problems in the process can submit issue or pr.
Stars: ✭ 24 (-73.63%)
Mutual labels:  router
svelte-starter-kit
Svelte starter kit — router, state management and testing included.
Stars: ✭ 16 (-82.42%)
Mutual labels:  router

middlewares/fast-route

Latest Version on Packagist Software License Testing Total Downloads

Middleware to use FastRoute for handler discovery.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/fast-route.

composer require middlewares/fast-route

You may also want to install middlewares/request-handler.

Example

This example uses middlewares/request-handler to execute the route handler:

//Create the router dispatcher
$dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
    $r->addRoute('GET', '/hello/{name}', function ($request) {
        //The route parameters are stored as attributes
        $name = $request->getAttribute('name');

        //You can echo the output (it will be captured and written into the body)
        echo sprintf('Hello %s', $name);

        //Or return a string
        return sprintf('Hello %s', $name);

        //Or return a response
        return new Response();
    });
});

$dispatcher = new Dispatcher([
    new Middlewares\FastRoute($dispatcher),
    new Middlewares\RequestHandler()
]);

$response = $dispatcher->dispatch(new ServerRequest('/hello/world'));

FastRoute allows anything to be defined as the router handler (a closure, callback, action object, controller class, etc). The middleware will store this handler in a request attribute.

Usage

Create the middleware with a FastRoute\Dispatcher instance:

$route = new Middlewares\FastRoute($dispatcher);

Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument, that will be used to create the error responses (404 or 405). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$responseFactory = new MyOwnResponseFactory();

$route = new Middlewares\FastRoute($dispatcher, $responseFactory);

attribute

Changes the attribute name used to store the handler in the server request. The default name is request-handler.

$dispatcher = new Dispatcher([
    //Save the route handler in an attribute called "route"
    (new Middlewares\FastRoute($dispatcher))->attribute('route'),

    //Execute the route handler
    (new Middlewares\RequestHandler())->handlerAttribute('route')
]);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].