Slide 1

Slide 1 text

Amanda Folson - Laracon 2016 @AmbassadorAwsum Zero to API with Lumen

Slide 2

Slide 2 text

Who Am I? ▸ Amanda Folson ▸ Developer Advocate at GitLab ▸ Professional Conference Attendee ▸ OSS ~10 years ○ Many years of APIs

Slide 3

Slide 3 text

About Lumen ▸ Microframework ▸ Circa April 2015 ▸ Trimmed down Laravel ▸ Laravel upgrade path

Slide 4

Slide 4 text

Why Lumen?

Slide 5

Slide 5 text

Monolithic->Microservices

Slide 6

Slide 6 text

Blacklist Build Zones Honeypot API Scheduler Thing Restarter

Slide 7

Slide 7 text

What the heck is an API?

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

HTTP-based APIs ▸ Often HTTP-based ○ Many things natively speak HTTP ▸ Stateless ○ No sessions! ○ HATEOAS

Slide 10

Slide 10 text

HTTP Methods OPTIONS GET DELETE PATC H PUT POST

Slide 11

Slide 11 text

Coming From Laravel

Slide 12

Slide 12 text

Getting Started

Slide 13

Slide 13 text

DotEnv

Slide 14

Slide 14 text

Facades + Eloquent

Slide 15

Slide 15 text

Routing Laravel Routing Lumen Routing

Slide 16

Slide 16 text

Artisan

Slide 17

Slide 17 text

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`

Slide 18

Slide 18 text

Migrations ▸ Install ▸ Refresh ▸ Reset ▸ Rollback ▸ Status ▸ `db:seed`

Slide 19

Slide 19 text

Make Migrations

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Pokémon API

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Resource Collections

Slide 24

Slide 24 text

Pokédex Routes

Slide 25

Slide 25 text

A Note About Views...

Slide 26

Slide 26 text

JSON

Slide 27

Slide 27 text

Fractal

Slide 28

Slide 28 text

Pokémon Controller - Index and Store

Slide 29

Slide 29 text

Pokémon Controller - Show

Slide 30

Slide 30 text

Pokémon Controller - Update

Slide 31

Slide 31 text

Pokémon Controller - Destroy

Slide 32

Slide 32 text

Pokémon Model

Slide 33

Slide 33 text

Authentication ▸ AuthServiceProvider provided ○ But needs to be uncommented in app.php ▸ PLENTY of other options ○ JWT

Slide 34

Slide 34 text

Using Authentication Middleware ▸ Many packages available (JWT, OAUTH2, Stormpath, etc.) ▸ JWT used below:

Slide 35

Slide 35 text

A Note About Authentication...

Slide 36

Slide 36 text

Testing

Slide 37

Slide 37 text

Beyond This Talk ▸ HATEOAS and Hypermedia ▸ Rate limiting ▸ Running APIs at scale ▸ Events ▸ Queues ▸ Caching ▸ Encryption ▸ Logging ▸ Deploying

Slide 38

Slide 38 text

/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!

Slide 39

Slide 39 text

Thank You! Amanda Folson - @AmbassadorAwsum [email protected]