|
| 1 | +# Overview |
| 2 | + |
| 3 | +Expressive allows you to write [PSR-7](http://www.php-fig.org/psr/psr-7/) |
| 4 | +[middleware](https://github.com/zendframework/zend-stratigility/blob/master/doc/book/middleware.md) |
| 5 | +applications for the web. |
| 6 | + |
| 7 | +PSR-7 is a standard defining HTTP message interfaces; these are the incoming |
| 8 | +request and outgoing response for your application. By using PSR-7, we ensure |
| 9 | +that your applications will work in other PSR-7 contexts. |
| 10 | + |
| 11 | +Middleware is any code sitting between a request and a response; it typically |
| 12 | +analyzes the request to aggregate incoming data, delegates it to another layer |
| 13 | +to process, and then creates and returns a response. Middleware can and should |
| 14 | +be relegated only to those tasks, and should be relatively easy to write and |
| 15 | +maintain. |
| 16 | + |
| 17 | +Middleware is also designed for composability; you should be able to nest |
| 18 | +middleware and re-use middleware. |
| 19 | + |
| 20 | +With Expressive, you can build PSR-7-based middleware applications: |
| 21 | + |
| 22 | +- APIs |
| 23 | +- Websites |
| 24 | +- Single Page Applications |
| 25 | +- and more. |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +Expressive builds on [zend-stratigility](https://github.com/zendframework/zend-stratigility) |
| 30 | +to provide a robust convenience layer on which to build applications. The |
| 31 | +features it provides include: |
| 32 | + |
| 33 | +- **Routing** |
| 34 | + |
| 35 | + Stratigility provides limited, literal matching only. Expressive allows you |
| 36 | + to utilize dynamic routing capabilities from a variety of routers, providing |
| 37 | + much more fine-grained matching capabilities. The routing layer also allows |
| 38 | + restricting matched routes to specific HTTP methods, and will return "405 Not |
| 39 | + Allowed" responses with an "Allow" HTTP header containing allowed HTTP |
| 40 | + methods for invalid requests. |
| 41 | + |
| 42 | + Routing is abstracted in Expressive, allowing the developer to choose the |
| 43 | + routing library that best fits the project needs. By default, we provide |
| 44 | + wrappers for Aura.Router, FastRoute, and the zend-mvc router. |
| 45 | + |
| 46 | +- **contaienr-interop** |
| 47 | + |
| 48 | + Expressive encourages the use of Dependency Injection, and defines its |
| 49 | + `Application` class to compose a container-interop `ContainerInterface` |
| 50 | + instance. The container is used to lazy-load middleware, whether it is |
| 51 | + piped (Stratigility interface) or routed (Expressive). |
| 52 | + |
| 53 | +- **Templating** |
| 54 | + |
| 55 | + While Expressive does not assume templating is being used, it provides a |
| 56 | + templating abstraction. Developers can write middleware that typehints on |
| 57 | + this abstraction, and assume that the underlying adapter will provide |
| 58 | + layout support and namespaced template support. |
| 59 | + |
| 60 | +- **Error Handling** |
| 61 | + |
| 62 | + Applications should handle errors gracefully, but also handle them differently |
| 63 | + in development versus production. Expressive provides both basic error |
| 64 | + handling via Stratigility's own `FinalHandler` implementation, as well as |
| 65 | + more advanced error handling via two specialized error handlers: a templated |
| 66 | + error handler for production, and a Whoops-based error handler for development. |
0 commit comments