Lessons learned while transitioning to an API company - how to structure applications in a sane way and use modern tools to make and maintain a codebase you won't hate.
2. 6 THINGS I WISH I HAD
KNOWN
1. MVC frameworks aren’t designed for APIs
2. Modern tools are awesome; use them
3. Write testable code
4. Make deployment easy & scalable
5. Make your infrastructure work for you
6. Break down app into smaller services
3.
4. MVC FRAMEWORKS
• Popularized by Ruby on Rails
• Opinionated design optimized for building
quickly
• Convention over configuration
5. ✅ Fast prototyping
✅ Reasonably sane architecture
❌ Inflexible structure
❌ Tightly coupled
❌ Unsuitable for non-web tasks
💣 Active Record pattern
7. –Benjamin Franklin*
“Always code as if the guy who ends up
maintaining your code will be a violent
psychopath who knows where you live.”
* Martin Golding
12. Most common problems are already solved
Focus on using libraries
…but build them independently when
necessary
Contribute fixes back upstream if possible
13. WHAT DOES EVERY API
NEED?
Authentication
Request & Response formats
Documentation
22. TESTABLE CODE
Support DI; hint interfaces, not classes
Red flags: “new”, “and”, “::”, “instance”, “->->->”
More small classes & methods
Make tests reusable
Write tests first! (TDD)
23.
24. TESTING SERVICES
• Mock response from service w/ different
results
• Test output formats
• Trust required
42. 6 THINGS I WISH I HAD
KNOWN
1. MVC frameworks aren’t designed for APIs
2. Modern tools are awesome; use them
3. Write testable code
4. Make deployment easy & scalable
5. Make your infrastructure work for you
6. Break down app into smaller services