Welcome to the API of your dreams
Bonjour. Welcome to this series on how to build a cool REST API in Laravel 5. APIs are all around us. Most of us have tried integrating a third party into our app by consuming their API. Whether it is creating issues in GitHub, authenticating using Facebook or tracking users in Intercom we utilize the power of APIs to enhance our own app.
What many developers do not realize is that building your own app using an API is not only super useful - it is also relatively easy to get started. If your business is powered by your own API it becomes easier building and maintaining multiple clients (e.g. a desktop app, a smartphone app, tablet app etc.) since they all utilize the same business platform (the API).
Anywho, this is NOT an introduction to REST APIs
There are already plenty of good resources on how to get introduced into the world of APIs. Therefore this will not be another introduction into what a resource is, or how URLs should be formatted.
So what are we going to do?
This 5-part series will go over implementation details of specific challenges that I have faced in developing the Traede API
The first part is about how we can structure our API, so that it will not blow up in our face once it grows in complexity. We will take a stab at structure on three different levels:
- Application flow pattern
- Project folder structure
- Resource folder structure
The second part will be building resources. Building resources in itself is pretty easy, however the fun part becomes giving our consumers controls like filters, pagination and nested relationship controls.
We will try to implement some of my own Laravel API libraries in order to achieve this.
Part 3: Error handling
I will take you through some of the steps we have taken to increase the effictiveness of our error handling. This includes writing a custom exception handler that logs exceptions in Sentry - an online exception tracker service.
Part 4: Authentication
Almost any API needs some sort of authentication. I have already written a bit about how OAuth can be implemented in the Lumen framework.
In this series we will also be using OAuth for authentication, however we will be using Laravel's own implementation of The PHP League's OAuth Server: Laravel Passport.
Part 5: Inbound & outbound webhooks
A really kick ass API can integrate with other APIs. This can often happen through webhooks. We will look at how you can handle input from other APIs as well as how you can enable consumers to integrate with your API using outbound webooks.