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 withRouting, middleware, PSR-7 request/responseORM, templating, auth, mail, queues, and more — all built in
Best forAPIs, small apps, microservices, learning the underlying conceptsLarge applications that need everything out of the box
Learning curveSmall — a handful of core conceptsLarger — 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?

ReasonWhat it means for you
Great for APIsMinimal overhead, perfect for JSON REST APIs and microservices
PSR standardsBuilt on PSR-7 (HTTP messages) and PSR-11 (containers) — skills that transfer to other frameworks
Easy to understandSmall codebase means you can actually read how it works under the hood
Composer-basedA 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.