Phil Sturgeon on building APIs in any language and PHP 7
Interviewed by Christophe Limpalair on 04/09/2015
If this interview helps you in any way, check out his book Build APIs You Won't Hate, which we talk about in the interview. Enjoy!
Phil Sturgeon is probably a name you've seen before. He was a member of PHP-FIG, he built PyroCMS, wrote a book, and he also bikes a lot. Phil has actually had a lot of people try and impersonate him. Don’t just take my word for it—
As you can see, impostors took over PHP Reddit about a week ago. Rest assured, this interview is of the real Phil Sturgeon.
The real Phil Sturgeon wrote a book called Build APIs You Won't Hate. I wanted to learn more about APIs and I wanted to get PHP news that you may not have heard of just yet, so that's what this interview is about. He also tells us which tools he uses to push code live, and he explains how dependency injection works.
The reason I wanted to talk about APIs and ended up spending most of the interview doing just that, is because so many companies are asking their developers to build them. I really think that this interview, his book, and your follow up practice, will make you a more valuable developer.
If your company asks you to build an API, you will already have an idea of how to get started and avoid common mistakes.
If you've already built an API and aren't completely satisfied with it, you will be able to go back and make it even better.
In this interview, we cover a lot of steps including:
- First Steps - Database seeding and planning
- Creating Endpoints - What our Controllers, Models, and Routes will look like
- Inputs & Outputs - Requests and Responses (Example on line 1)
- Testing APIs - See tools below
- Outputting Data - Two examples on line 16
- Data Relationships - Not outputting too much info in one request (very heavy & slow), and yet not having too many requests
- Debugging - See tools below
- Documentation - See tools below
Here are a few tools to help you out:
- Wireshark - Interpret and interact with packet data
- Postman - Make API workflow faster
- API Blueprint - Documentation-oriented API description language
- Dredd - Command-line tool to validate API docs
In the interview, it starts at 53:44.
For the longest time, I just couldn't see the benefit of dependency injection. It just seemed like code was moved around a little bit and I couldn't understand why that was important. But finally it clicked, and I wanted to share what made me understand it with the hope that others would understand it in less time than it took me. So if you're still not sure why dependency injection matters, read on, otherwise feel free to skip this section.
I asked Phil to explain it for us. I think he did a great job of explaining it, and here is the example I used in the interview:
Here's the dependency injection example (starting on line 45)
What Phil uses to deploy
In the interview, it starts at 57:50.
He explains some of the things Chef can do in a nutshell. But these days, he uses Heroku quite a bit. Why? Because of its simplicity and not having to mess with servers. Of course, this will be a bit more expensive but that may be a trade-off you're willing to accept.
This part starts at 1:03:20 in the interview.
Any exciting news? Phil talks about a few features in PHP 7 -- everything is becoming a lot more consistent. The language itself is growing up and unexpected behaviors are going away.
Rasmus created a Vagrant box for PHP7 so you can play around with it.
PSR-7 is the HTTP message PSR. Matthew Weier O'Phinney wrote a very detailed post about it which I recommend you check out.
If you want to get in touch with Phil, his website is https://philsturgeon.uk/, and you can find him on Twitter at @philsturgeon
Thanks for watching!
How did this interview help you?
If you learned anything from this interview, please thank our guest for their time.
Oh, and help your followers learn by clicking the Tweet button below :)