Learning at Work Week: What is Lumen?
19 May 2017 |
Claudia Green | About a 2 minute read
Lumen is a PHP “micro-framework”; an extremely fast, smaller version of the full web-app framework Laravel, but without the view layer. Made by the same creator as Laravel, it is a framework that focuses solely on serving stateless, JSON APIs and enables you to build a pretty powerful system with an off-the-shelf tool.
On a default installation, Lumen has a slimmed down folder structure, with no resources or databases directories and, by default, many of its features are disabled and need to be ‘activated’ (uncommented) before they can be used. Like Laravel, there is no config directory with multiple files – Lumen makes use of the same .env library with just the one file to configure the whole application.
Since Lumen is a play on the ‘Illuminate’ components that Laravel utilizes, it has all the power of Laravel’s components (such as Eloquent, databases, & caching) straight out of the box. Lumen still allows you to use controllers with full dependency injection, as well as middleware to protect your routes, & to do some filtering before the requests enter your application.
It also ‘upgrades’ fairly easily to the full-stack Laravel framework should you realise you need it – although there is the flexibility to pull in individual Laravel components to extend Lumen, enabling you to use it for more than just micro-services and APIs should you wish. If your intention is to create a full user-facing application, however, you may as well just use Laravel.
Recently I’ve been using Lumen to write a push notification service for an Ionic Cordova iOS/Anrdoid app. When testing, Lumen allows us to create mocks, has been great for TDD-ing and it also plays really well with external libraries. In as little as around 20 lines we were able to write our own provider to do authentication that fits nicely into Lumen’s middleware structure.
Lumen’s biggest appeal is its performance. By sacrificing some of Laravel’s flexibility in terms of configuration, Lumen is much faster, and can handle far more requests per second than Laravel, or similar micro-frameworks such as Slim or Silex (1900 requests/second for Lumen, versus Slim 3’s 1800 or Silex’s 1000 – according to Lumen’s docs).
Lead and inspire a squad to succeed, bringing your passion for managing and developing people through career coaching and mentoring.I'm Interested
Graduate Developer (Halifax)
Kickstart your career in tech, building innovative web applications and software solutions with the latest technology and Agile development methodologies.I'm Interested
Digital Transformation People Consultant
Empower clients with the right operating models, organisation structures, ways of working and cultural transition.I'm Interested