PHPackages                             netolabs/php-lambda-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. netolabs/php-lambda-router

ActiveLibrary[API Development](/categories/api)

netolabs/php-lambda-router
==========================

Route requests to controller actions using the AWS Lambda handler

v0.1.0(5y ago)06201MITPHPPHP &gt;=7.3

Since Aug 27Pushed 4y ago3 watchersCompare

[ Source](https://github.com/NetoECommerce/php-lambda-router)[ Packagist](https://packagist.org/packages/netolabs/php-lambda-router)[ RSS](/packages/netolabs-php-lambda-router/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (10)Versions (2)Used By (0)

php-lambda-router
=================

[](#php-lambda-router)

Simple handler-based router middleware for the [php-lambda-runtime](https://github.com/NetoECommerce/php-lambda-runtime) library.

Installation
------------

[](#installation)

Run `composer require netolabs/php-lambda-router netolabs/php-lambda-runtime` from the root of your project.

Using the Router Middleware
---------------------------

[](#using-the-router-middleware)

The Router middleware is used to route our Lambda to a Controller and Action, much like an MVC framework would. The difference being that instead of routing based on the request path, we use the Lambda handler name. This allows us to have multiple Lambda functions inside the same repository and also allowing more reuse of code.

The handler name is expected in the format of "controller.action". Internally, the router will attempt to load the controller and check if the action method exists. If not, it will pass the request on to the next middleware in the queue; usually a fallback or a 404 middleware.

For example: if the handler name is helloworld.get, the router will attempt to load the `\App\Controller\HelloworldController` class and execute the method `getAction($request)`.

The default namespace is `\App\Controller\`, however this is configurable via constructor parameter.

Example
-------

[](#example)

### Adding the Router middleware

[](#adding-the-router-middleware)

In this example we're using the Router to route our Lambda to a Controller and Action. It includes an exception handler and a fallback which returns a 404 response if the route isn't matched. In your `app.php` use the following code:

```
