Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lumen in 5 minutes - learnt @hack24

Lumen in 5 minutes - learnt @hack24

A description of laravel's lumen microframework which i looked at when at nottingham hackathon @hacktwentyfour

Shaun Hare

May 04, 2015
Tweet

More Decks by Shaun Hare

Other Decks in Programming

Transcript

  1. A quick walk around Lumen > a quick tour of

    lumen composer require @sdh100shaun & 5 mins learnt at @Hack24
  2. Hacks like meetups are great place to learn things -

    like a mouse is hard to spot on a 4K screen
  3. Setting up - install > a quick tour of lumen

    composer based of course - can use create- project composer global require "laravel/lumen-installer=~1.0" then lumen new <project name> service
  4. Project Structure - Laravel 5 > a Laravel 5 esk

    structure missing some folders - database / resources etc as lightweight but core app the same service
  5. Project Structure - Laravel 5 > a Laravel 5 esk

    structure missing some folders - database / resources etc as lightweight but core app the same service
  6. Project Structure - Laravel 5 like > a Laravel 5

    esk structure missing some folders - database / resources etc as lightweight but core app the same service
  7. Things you will probably want to do > starting your

    project you will probably want environmental configuration so in bootstrap/app.php - uncomment // Dotenv::load (__DIR__.'/../'); and rename .env.example to .env
  8. Things you will probably want to do > starting your

    project it’s likely a micro-service you will probably want to do some request/response interaction (api-key, filtering , content negotiation,csrf) so turn on middleware - these things can live here // $app->routeMiddleware([]); guess how - becoming a pattern right
  9. Need db or cache or queue? > must store all

    the things and keep it fast Need a db , cache or queue php artisan make database - sets up folder structure with seeds, migrations (enable eloquent in app if required) Queuing ready just enable in config , pull package and write jobs in app/jobs Cache - just use the cache-driver setting in .env
  10. set up a route > in HTTP/routes.php similar to Laravel

    not exactly though can be inline $app->get('{path:.*}', function($path) { echo 'url is ' . $path; }); can be all done in line or can point to controller of course
  11. So why lumen - speed & familiarity > does it

    seem fast ? Yes .. In benchmarks - only phalcon can beat it http://taylorotwell.com/how-lumen-is- benchmarked/ • Silex: 950 requests per second • Slim: 1250 requests per second • Lumen: 1700 requests per second Premature optimisation is important right !!
  12. extra - blooper reel > things that caught me out

    in sleep deprived state Lumen is following laravel versioning - so all ready on 5.0.x I thought blade is not out of the box cos I could not get - index.blade.php to work - turns out {{ HTML:: script('resources/js/bootstrap.min.js') }} in view when html no longer in L5 core not good need to enable facades for schema::create to work