One API to Rule Them All
Hey, I’ve become comfortable with a specific setup for my personal projects. But realized that I ended up repeating many things on the backend.
I decided to create a single API (instance) to share between them.
My usual setup for personal projects
As a web developer I am, more often than not these projects are some kind of webapp.
I usually structure them by separating frontend and backend.
For the frontend I create a basic ReactJS app.
ℹ️ Recently I am trying to simplify this even more by using just HTML and JS.
For the backend, it’s always PHP. Which I like and enjoy using. I enjoy it so much, that I tend to get a bit excited and end up doing more than is really needed.
The backend and the frontend communicate through an API. And I got a bit exhausted of repeating always the same boilerplate and basic setup.
Meet the single API
So in the hopes of reducing friction I decided to create “One API to Rule them all” (I don’t even like The Lord of the Rings that much, but I couldn’t resist).
What I did is: https://api.aaron.com.es
.
It’s in very early stages, let me share with you some details about the actual implementation.
I experimented with a no-framework approach. Looking backwards I would not do it again; I would use Slim Framework, which is quite close to what I ended up using.
At the time of writing this I am using the following dependencies:
- PHP 8.3
- PHP-DI – for dependency injection.
- FastRoute – for, well… fast routing.
- Symfony’s Dotenv – for managing configuration variables
That’s all I needed to create my initial set of APIs.
A part from that, I am using a MySQL server (with a single database at the moment, which I share) and some external libraries (like SendGrid’s to send emails).
Right now, I consider this decision a success. I have already implemented a few endpoints, that I use almost daily.
I am being a bit vague on purpose, because I don’t want to share too much details on the APIs I am implementing there yet.
👂 If you think you would enjoy checking out the API codebase let me know (via email or twitter or liking this post really hard) and I will opensource it.
An example of an API I have implemented is the one I use for the Likes in this blog.
What’s next?
Some future ideas I have are:
- Implement some shared users/sessions management.
- Implement some basic analytics (and drop Google Analytics).
- Add some rate limiter; which will be accessible immediately to all APIs. (Cool, right?)
- Opening some parts of it for others to use.
This has been already much fun (and useful). Let me know if it was interesting to you by clicking the like button below… Psst! It sends me an email for every like I get that makes my day better!