Announcing Expressive 1.0.0RC1!

      2 Comments on Announcing Expressive 1.0.0RC1!

Today, we are pleased to announce the immediate availability of the first release candidate of Expressive, a PSR-7 middleware microframework.

Expressive allows you to write PSR-7 middleware applications for the web.

PSR-7 is a standard defining HTTP message interfaces; these are the incoming request and outgoing response for your application. By using PSR-7, we ensure that your applications will work in other PSR-7 contexts.

Middleware is any code sitting between a request and a response; it typically analyzes the request to aggregate incoming data, delegates it to another layer to process, and then creates and returns a response. Middleware can and should be relegated only to those tasks, and should be relatively easy to write and maintain.

Middleware is also designed for composability; you should be able to nest middleware and re-use middleware anywhere that supports PSR-7.

With Expressive, you can build PSR-7-based middleware applications:

  • APIs
  • Websites
  • Single Page Applications
  • and more.

Features

Expressive builds on zend-stratigility, our middleware foundation, to provide a robust convenience layer on which to build applications. The features it provides include:

  • Routing

    Stratigility provides limited, literal matching only. Expressive allows you to utilize dynamic routing capabilities from a variety of routers, providing much more fine-grained matching capabilities. The routing layer also allows restricting matched routes to specific HTTP methods, and will return "405 Not Allowed" responses with an "Allow" HTTP header containing allowed HTTP methods for invalid requests.

    Routing is abstracted in Expressive, allowing the developer to choose the routing library that best fits the project needs. By default, we provide wrappers for Aura.Router, FastRoute, and the zend-mvc router, and recommend using FastRoute.

  • container-interop

    Expressive encourages the use of Dependency Injection, and defines its Application class to compose a container-interop ContainerInterface instance. The container is used to lazy-load middleware, whether it is piped (Stratigility interface) or routed (Expressive). We provide instructions for using Aura.Di, Pimple, and zend-servicemanager, recommending the latter.

  • Templating

    While Expressive does not assume templating is being used, it provides a templating abstraction. Developers can write middleware that typehints on this abstraction, and assume that the underlying adapter will provide layout support and namespaced template support. We provide support for Plates, Twig, and zend-view.

  • Error Handling

    Applications should handle errors gracefully, but also handle them differently in development versus production. Expressive provides both basic error handling via Stratigility’s own FinalHandler implementation, as well as more advanced error handling via two specialized error handlers: a templated error handler for production, and a whoops-based error handler for development.

Getting Started

The easiest way to get started with Expressive is to use the skeleton application and installer. The skeleton provides a generic structure for creating your applications, and prompts you to choose a router, dependency injection container, template renderer, and error handler from the outset.

1. Create a new project

First, we’ll create a new project, using Composer’s create-project command:

This will prompt you to choose:

  • A router. We recommend using the default, FastRoute.
  • A dependency injection container. We recommend using the default, Zend ServiceManager.
  • A template renderer. You can ignore this when creating an API project, but if you will be creating any HTML pages, we recommend installing one. We prefer Plates.
  • An error handler. Whoops is a very nice option for development, as it gives you extensive, browseable information for exceptions and errors raised.

2. Start a web server

The Skeleton + Installer creates a full application structure that’s ready-to-go when complete. You can test it out using built-in web server.

From the project root directory, execute the following:

This starts up a web server on localhost port 8080; browse to http://localhost:8080/ to see if your application responds correctly!

Next Steps

From here, it’s time to start writing middleware!

We recommend reading our quick start, which provides some tips and hints for writing your first middleware, and then reading the full documentation to see the various features you can leverage.

Welcome to the new era of PHP!