Slim Framework Tutorial
Slim is a PHP micro-framework — a small, focused toolkit for building web applications and APIs quickly, without the weight of a full-stack framework like Laravel or Symfony. It gives you routing, middleware, and request/response handling, and gets out of your way otherwise.
Where this fits: Everything you learned in Core PHP — variables, arrays, OOP, PDO, sessions — still applies here. Slim doesn't replace PHP; it just organizes how your PHP code handles incoming web requests.
Micro-Framework vs Full-Stack Framework
| Micro-framework (Slim) | Full-stack (Laravel, Symfony) | |
|---|---|---|
| Comes with | Routing, middleware, PSR-7 request/response | ORM, templating, auth, mail, queues, and more — all built in |
| Best for | APIs, small apps, microservices, learning the underlying concepts | Large applications that need everything out of the box |
| Learning curve | Small — a handful of core concepts | Larger — many conventions to learn |
A Quick Look Ahead
Example: A Complete Slim App in a Few Lines
<?php
require __DIR__ . '/../vendor/autoload.php';
$app = \Slim\Factory\AppFactory::create();
// Define a route
$app->get('/hello/{name}', function ($request, $response, $args) {
$response->getBody()->write("Hello, " . $args['name'];
return $response;
});
$app->run();
Note: This code is a correct, real Slim example — but this website itself doesn't run Composer/Slim, so you won't see it executed live on this page. Copy it into your own Slim project (after installing Slim via Composer on the next page) to actually run it.
Why Learn Slim?
| Reason | What it means for you |
|---|---|
| Great for APIs | Minimal overhead, perfect for JSON REST APIs and microservices |
| PSR standards | Built on PSR-7 (HTTP messages) and PSR-11 (containers) — skills that transfer to other frameworks |
| Easy to understand | Small codebase means you can actually read how it works under the hood |
| Composer-based | A great first project to practice modern PHP dependency management |
Next steps: Head to Installation & Setup to install Slim via Composer and see the project structure.