Application Programming Interfaces, otherwise known as APIs, have been a passion of mine for several years. I have been building them in multiple languages and frameworks for a long time. They started off bad, and I mean really bad. I didn't know what I was doing - I was just trying to find a way to get it to work. It wasn't until I read the "Build APIs you won't hate" book by Phil Sturgeon that I started to understand where I had been going wrong.
Most of the APIs I build these days are REST APIs, and this is where I notice many people going wrong in their approach. They think REST APIs can just be JSON wrappers around their database tables, allowing programmatic external access. If this isn't the case, people tend not to think about what they are trying to build.
As developers, we spend countless hours diving into the user experience of our applications, and companies spend thousands on researchers and designers to optimize their applications for their users and sales funnel. But their APIs? Nope, most organizations will limit their investment in this area. I have always firmly believed that if a job is worth doing, it is worth doing properly.
This book will walk through how to build an API using the Laravel framework, taking your REST API to the next level, and going through step-by-step so you can take your API from REST to the best.
We will cover more advanced topics on how you can build a successful and scalable API in Laravel. Now when we talk about scaling, we aren't just talking about scaling the amount of traffic our API can handle but also scaling out the complexity of our API and how many developers can efficiently work on it simultaneously. Key areas we will cover include Authentication and Authorization, Caching Strategies, Efficient Responses, and utilizing background Jobs to handle processing.
Building APIs is relatively easy, but building a good API - this is where the hard work starts. You need to understand your users and their use cases, what will be helpful to them, and why they might be using your API in the first place. All APIs need to be well-designed and have a strong purpose. What do I mean by purpose? Well, why do you have an API to start with? Is it an internal API, a public read-only API, or a way to enable your power users better access and control? Either way, understanding the why is a vital step before building any API.
So, what will we build to go through all of this? It has to be something with enough functionality to understand the process - but not too much logic to obfuscate the lessons we are trying to learn. Do we want to build a to-do app again? Most likely not. We will be building a calendar application that will allow people to define different types of events - and allow others to book time from these calendars. Similar to calendly or cal.com - but our version. This will allow us to investigate the different use cases that an integrator might have and some exciting challenges. We will start with a CRUD-style API and look at the steps we might need to take to refactor this API to be something even Phil Sturgeon would be proud of.
Let's dive into how we will start building amazing APIs in Laravel, using well-tested techniques that I have polished over the years - ensuring that we keep to an industry standard to increase our chances of success.