$method = ?;
$endpoint = ?;
$payload = ?;
$status = ?;
$app->{$method}($endpoint, function () {
/* The “easy” part */
return response($payload, $status)
});
Slide 7
Slide 7 text
Time to make
some design
decisions!
Slide 8
Slide 8 text
api.mygradebook.local
× Create an assignment
× Read assignments (single & multiple)
× Update an assignment
× Delete an assignment
Slide 9
Slide 9 text
What Should the
ENdpoints look like
and Which HTTP
Methods will we use?
Slide 10
Slide 10 text
GET
PUt
Delete
Options
POST
Patch
Head
Common HTTP Methods
Slide 11
Slide 11 text
GET
PUt (replace or create)
Delete
Options
POST (create/other)
Patch (update)
Head
Common HTTP Methods
Slide 12
Slide 12 text
api.mygradebook.local
POST /assignments - Create
GET /assignments - List/Search
GET /assignments/{id} – Read
PATCH /assignments/{id} - Update
DELETE /assignments/{id} - Delete
Slide 13
Slide 13 text
https://leanpub.com/restful-api-design
By:
Keith Casey
James Higginbotham
Mailing List:
“API Developer Weekly”
Slide 14
Slide 14 text
Status Codes?
Slide 15
Slide 15 text
503
Slide 16
Slide 16 text
503
SERVICE
UNAVAILABLE
Slide 17
Slide 17 text
201
Slide 18
Slide 18 text
201
CREATED
Slide 19
Slide 19 text
429
Slide 20
Slide 20 text
429
TOO MANY
REQUESTS
Slide 21
Slide 21 text
SHOULD the API
Version go in the URL
or in the HEaders?
Slide 22
Slide 22 text
URL
Slide 23
Slide 23 text
HEADERS
Slide 24
Slide 24 text
ELEPHPANT
Slide 25
Slide 25 text
application/json
Or
application/xml
Or...
Slide 26
Slide 26 text
HATEOAS?
HAL • JSON-LD
JSON-API • CUSTOM
And More
Slide 27
Slide 27 text
AUTH?
Slide 28
Slide 28 text
API AUTH
First Visit SSL? Later Visits Examples:
ID + Secret YES ID + Secret HTTP Basic Auth
ID + Secret YES ID + Token OAuth 2.0, JWT
ID + Signature PLZ ID + Signature Signature V4, OAuth 1.0a
Slide 29
Slide 29 text
APIS Are HARD!
× REST & HTTP
× API Versioning
× Status Codes
× Content Negotiation
× HATEOAS
× Auth
× Streams / Blobs
× Pagination
× Idempotency
× Rate Limiting
× CORS
× Response Caching
× Scalability & Perf.
× CAP Theorem
Slide 30
Slide 30 text
https://github.com/dingo/api
Slide 31
Slide 31 text
Dingo API
× Content negotiation
× Authentication adapters (inc. JWT & OAuth 2)
× API versioning (in the headers)
× Rate limiting middleware
× Response builder/transformers
Swagger
× Representation of your RESTful API
× JSON or YAML
× Large ecosystem
× Documentation generation
× Code generation
× Gateway integration (e.g., Amazon API Gateway)
APIS with Lumen, DINGO
FRACTAL, UUID, Guzzle,
OPENAPI (swagger),
BootPrint, & More
Slide 73
Slide 73 text
WHAT’s
MISSING?
Slide 74
Slide 74 text
HOW Can You Help?
× Publish a Swagger doc for your API
× Adopt a Swagger tool or make a new one
× Get involved in the OpenAPI group
× Improve Lumen/Laravel’s API ecosystem