Slim is a micro framework for PHP . We can build quickly powerful web applications and APIs. Slim is a dispatcher that receives an HTTP request, invokes an appropriate callback routine, and returns an HTTP response.
Slim is an ideal tool to create APIs that consume, repurpose, or publish data. Slim is also a great tool for rapid prototyping. Heck, we can even build full-featured web applications with user interfaces. More importantly, Slim is super fast and has very little code. In fact, we can read and understand its source code in only an afternoon!
First, we need a web server like Apache. We should configure our web server so that it sends all appropriate requests to one “front-controller” PHP file. We instantiate and run our Slim app in this PHP file.
A Slim app contains routes that respond to specific HTTP requests. Each route invokes a callback and returns an HTTP response. To get started, we first instantiate and configure the Slim application. Next, we define our application routes. Finally, we run the Slim application. It’s that easy. Here’s an example application:
Slim is designed to play well with other PHP components, too. We can register additional first-party components that build upon Slim’s default functionality. It’s also easy to integrate third-party components found on Packagist.
If anyone is new to Slim, I recommend to read this documentation from start to finish. If anyone is already familiar with Slim, she/he can instead jump straight to the appropriate section.
This documentation begins by explaining Slim’s concepts and architecture before venturing into specific topics like request and response handling, routing, and error handling.