I recently had to build an API for a client. The client is a content based business that prefers to utilize WordPress related technologies whenever possible. Since WordPress is built on top of PHP and I think it’s a good idea to limit the number of disparate technologies in any tech stack, I decided to stick to PHP solutions for the API development. After researching several different PHP micro frameworks I chose Slim.
So far my experiences with Slim have been great. It is easy to install and configure and performance is excellent. To get started, install PHP, install Composer, create a Composer config file and then run the Composer install command. This will create a directory structure with the main definition file index.php. This file is where you define your URLs and include external files such as the definition for your database connection and code relevant for specific URLs. This structure should be familiar to anyone who has used modern web development frameworks such as Rails or Django but I would like to stress how unbelievably easy it is to get up and running on Slim.
To finish your Slim configuration you will need to configure your web server of choice to work with Slim. I chose nginx as it seems best suited for an API application but Apache is also a popular choice.
Slim is a great choice for PHP developers that want a super simple and lightweight framework to host an API.