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

Zero to API With Lumen

Zero to API With Lumen

Ever wanted to create an API but weren't sure how to get started? Create APIs quickly with the Lumen PHP micro-framework.

F822f1d39cf52a0b934b9481472d7996?s=128

Amanda Folson

July 28, 2016
Tweet

Transcript

  1. Amanda Folson - Laracon 2016 @AmbassadorAwsum Zero to API with

    Lumen
  2. Who Am I? ▸ Amanda Folson ▸ Developer Advocate at

    GitLab ▸ Professional Conference Attendee ▸ OSS ~10 years ◦ Many years of APIs
  3. About Lumen ▸ Microframework ▸ Circa April 2015 ▸ Trimmed

    down Laravel ▸ Laravel upgrade path
  4. Why Lumen?

  5. Monolithic->Microservices

  6. Blacklist Build Zones Honeypot API Scheduler Thing Restarter

  7. What the heck is an API?

  8. REST APIs ▸ Representational State Transfer ▸ Can return XML,

    JSON, YAML, Markdown ▸ RAPIDLY gaining adoption over SOAP/XML-RPC ◦ No need to know order of parameters
  9. HTTP-based APIs ▸ Often HTTP-based ◦ Many things natively speak

    HTTP ▸ Stateless ◦ No sessions! ◦ HATEOAS
  10. HTTP Methods OPTIONS GET DELETE PATC H PUT POST

  11. Coming From Laravel

  12. Getting Started

  13. DotEnv

  14. Facades + Eloquent

  15. Routing Laravel Routing Lumen Routing

  16. Artisan

  17. Differences Between Laravel and Lumen in Artisan Lumen’s `artisan`: ▸

    No `serve` command ▸ No `key:generate` ▸ No `tinker` ▸ No `env` ▸ No `down` ▸ No `vendor:publish`
  18. Migrations ▸ Install ▸ Refresh ▸ Reset ▸ Rollback ▸

    Status ▸ `db:seed`
  19. Make Migrations

  20. Differences in Artisan’s Make Command Lumen’s `make`: ▸ ONLY has

    `make:migration` ▸ No `make:model` ▸ No `make:controller` ▸ No `make:auth` + scaffolding ▸ Many more since Lumen is slimmed down
  21. Pokémon API

  22. Resources ▸ /resource is a gateway to an area of

    an application ◦ In this case, we hit /pokemon ◦ We can get a single Pokémon or a collection of them
  23. Resource Collections

  24. Pokédex Routes

  25. A Note About Views...

  26. JSON

  27. Fractal

  28. Pokémon Controller - Index and Store

  29. Pokémon Controller - Show

  30. Pokémon Controller - Update

  31. Pokémon Controller - Destroy

  32. Pokémon Model

  33. Authentication ▸ AuthServiceProvider provided ◦ But needs to be uncommented

    in app.php ▸ PLENTY of other options ◦ JWT
  34. Using Authentication Middleware ▸ Many packages available (JWT, OAUTH2, Stormpath,

    etc.) ▸ JWT used below:
  35. A Note About Authentication...

  36. Testing

  37. Beyond This Talk ▸ HATEOAS and Hypermedia ▸ Rate limiting

    ▸ Running APIs at scale ▸ Events ▸ Queues ▸ Caching ▸ Encryption ▸ Logging ▸ Deploying
  38. /resources ▸ Lumen and Laravel docs ◦ https://lumen.laravel.com/docs/ ▸ Paul

    Redmond’s Book ◦ https://www.apress.com/9781484221860 ▸ Build APIs You Won’t Hate by Phil Sturgeon ▸ RESTful Web APIs by Leonard Richardson, Mike Amundsen, and Sam Ruby ▸ Undisturbed REST by Mike Stowe ▸ Me!
  39. Thank You! Amanda Folson - @AmbassadorAwsum amanda@gitlab.com