I was playing around with Slim Framework recently, and decided to write-up another article about it, since it’s such a breeze. The original post highlighted how simple it was to get your Get, Post, Put, and Delete all wired up and ready to do work. This post will show how to create a little class that utilizes Slim and could serve as a launching point to building your own RESTful API. I’m planning one last post on Slim which will show how to use jQuery to do Puts and Deletes (since modern browsers typically only support Gets and Posts), make the API responses more useful, and how to use Slim’s middleware support to limit the API to valid users.
Time for a QuickNap
To make things more manageable, I created a new class for the API implementation. It’s bare bones at the moment and takes the DB connection information as arguments for its constructor.
require 'lib/QuickNap/QuickNap.php';
$dbUser = "api";
$dbPass = "shhhhhhhhhhhhh";
$dbHost = "localhost";
$dbName = "api";
$quickNap = new \QuickNap\QuickNap($dbHost, $dbName, $dbUser, $dbPass);
$quickNap->enable();
Continue reading →