All Projects → amphp → http-server-router

amphp / http-server-router

Licence: MIT License
A router for Amp's HTTP Server.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to http-server-router

CRRouter
A simple and powerful router
Stars: ✭ 54 (+92.86%)
Mutual labels:  router
OpenBSDFirewall
Simple OpenBSD Home Firewall Config for ALIX Board
Stars: ✭ 41 (+46.43%)
Mutual labels:  router
slim-wrt
Armor for Openwrt
Stars: ✭ 66 (+135.71%)
Mutual labels:  router
framework
Lite & fast micro PHP framework that is **easy to learn**.
Stars: ✭ 110 (+292.86%)
Mutual labels:  router
retil
The React Utility Library
Stars: ✭ 46 (+64.29%)
Mutual labels:  router
tarojs-router-next
Taro 小程序路由库/自动生成带参数类型提示的路由方法/允许传递任意类型、任意大小的参数数据/同步的路由方法调用/koa体验一致的路由中间件
Stars: ✭ 166 (+492.86%)
Mutual labels:  router
boring-router
A type-safe MobX router with parallel routing support.
Stars: ✭ 74 (+164.29%)
Mutual labels:  router
amphp.github.io
Main website repository.
Stars: ✭ 21 (-25%)
Mutual labels:  amphp
shim
HTTP Handler shim for Go projects running on AWS Lambda
Stars: ✭ 64 (+128.57%)
Mutual labels:  router
MVVM-Sample
Swift MVVM Sample project. Made with ReactiveCocoa, Swinject and Routers
Stars: ✭ 21 (-25%)
Mutual labels:  router
UserDeviceTracker
快速定位一个IP或MAC在你的网络中的位置,是网络工程师提高工作效率的利器,也可以为CMDB提供基础网络数据。
Stars: ✭ 36 (+28.57%)
Mutual labels:  router
amber-router
A URL Routing shard.
Stars: ✭ 16 (-42.86%)
Mutual labels:  router
svelte-router
Router component for Svelte
Stars: ✭ 63 (+125%)
Mutual labels:  router
YAWAC
Yet Another Wifi Auto Connect (YAWAC) is a shell script to connect to a dataset of wireless connection and free hotspot like FreeWifi. It's works on OpenWrt.
Stars: ✭ 22 (-21.43%)
Mutual labels:  router
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (+139.29%)
Mutual labels:  router
bs-director
[UNMAINTAINED] BuckleScript bindings to the Director router
Stars: ✭ 22 (-21.43%)
Mutual labels:  router
Router
The Hoa\Router library.
Stars: ✭ 29 (+3.57%)
Mutual labels:  router
appsync-resolvers
AWS AppSync Resolvers for GraphQL using AWS Lambda functions in Go.
Stars: ✭ 37 (+32.14%)
Mutual labels:  router
nativescript-vue-router
A simple router implementation that is suitable for NativeScript-Vue.
Stars: ✭ 14 (-50%)
Mutual labels:  router
spirit-router
fast router for spirit
Stars: ✭ 28 (+0%)
Mutual labels:  router

http-server-router

This package provides a routing RequestHandler for Amp's HTTP server based on the request URI and method based on FastRoute.

Installation

This package can be installed as a Composer dependency.

composer require amphp/http-server-router

Usage

Router implements RequestHandler. Any attached RequestHandler and Middleware instances will receive any ServerObserver events.

Routes can be defined using the addRoute($method, $uri, $requestHandler) method. Please read the FastRoute documentation on how to define placeholders.

Matched route arguments are available in the request attributes under the Amp\Http\Server\Router key as an associative array.

Example

$router = new Router;

$router->addRoute('GET', '/', new CallableRequestHandler(function () {
    return new Response(Status::OK, ['content-type' => 'text/plain'], 'Hello, world!');
}));

$router->addRoute('GET', '/{name}', new CallableRequestHandler(function (Request $request) {
    $args = $request->getAttribute(Router::class);
    return new Response(Status::OK, ['content-type' => 'text/plain'], "Hello, {$args['name']}!");
}));

Limitations

The Router will decode the URI path before matching. This will also decode any forward slashes (/), which might result in unexpected matching for URIs with encoded slashes. FastRoute placeholders match path segments by default, which are separated by slashes. That means a route like /token/{token} won't match if the token contains an encoded slash. You can work around this limitation by using a custom regular expression for the placeholder like /token/{token:.+}.

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].