Slim
By Slim Framework Team
Slim is a lightweight PHP micro-framework for building web applications and HTTP APIs with minimal built-in overhead. It provides a router, a middleware pipeline, and a dependency injection container, but leaves choices such as templating…
Definition
Slim is a lightweight PHP micro-framework for building web applications and HTTP APIs with minimal built-in overhead. It provides a router, a middleware pipeline, and a dependency injection container, but leaves choices such as templating engines, database libraries, and validation tools entirely to the developer, following the PHP-FIG PSR standards so it can be combined with a wide range of interchangeable third-party components.
Overview
Full-stack frameworks like Symfony or Laravel bundle ORM layers, templating engines, and many other subsystems by default, which is convenient for full applications but adds weight and decisions that aren't always needed, particularly for small services or APIs. Slim takes the opposite position: it provides only routing, middleware, and dependency injection as its core, and expects developers to bring in whichever additional libraries they need for the rest. Mechanically, a Slim application defines routes that map HTTP methods and URL patterns to callable handlers, and every request passes through a middleware pipeline before reaching its route handler, allowing cross-cutting concerns such as authentication, CORS handling, or request logging to be layered on independently of route-specific logic. Because Slim implements the PSR-7 HTTP message interfaces and PSR-15 middleware standard defined by the PHP Framework Interop Group, any PSR-7-compatible request and response object, and any PSR-15-compatible middleware, can be used inside a Slim application without custom adapters, which is a deliberate design choice to maximize interoperability with the broader PHP ecosystem rather than building a closed set of first-party tools. Among PHP frameworks, Slim is positioned closer to Express.js in Node.js or Sinatra in Ruby than to full-stack frameworks like Symfony or Laravel: it solves routing and middleware composition and stops there, leaving an application's data layer, templating, and validation entirely up to the developer's choices. This makes Slim smaller in scope than something like Yii or Symfony, both of which bundle an ORM, templating engine, and code generation tooling as part of the core offering. In practice, Slim is chosen for building small to medium REST APIs, microservices, and backend-for-frontend layers where a team wants precise control over which libraries are included rather than inheriting a framework's default stack. It is also used in teaching contexts and prototypes because its small surface area makes the request lifecycle easier to understand end to end. The trade-off is that Slim provides less out of the box: teams must select and integrate their own database access layer, validation library, and templating engine if one is needed, which requires more upfront architectural decisions than a full-stack framework would. For very large applications with many interacting modules, the lack of enforced conventions can lead to inconsistent patterns across a codebase unless a team establishes its own standards early. As a project grows, some teams find they have effectively reassembled a subset of a full-stack framework's feature set piece by piece, at which point migrating to Symfony or Laravel may reduce ongoing maintenance overhead compared to continuing to maintain a bespoke collection of Slim-compatible libraries.
Key Features
- Minimal core focused on routing, middleware, and dependency injection
- Full PSR-7 and PSR-15 compliance for interoperability with other PHP libraries
- Middleware pipeline for composing cross-cutting request handling
- No bundled ORM or templating engine, leaving those choices open
- Small codebase that is straightforward to read end to end
- Supports dependency injection containers compatible with PSR-11
- Well suited to building focused REST APIs and microservices