ConfigsJul 1, 2026·3 min read

Slim — Lightweight PHP Micro Framework for REST APIs

Slim is a PHP micro framework that helps you write simple yet powerful web applications and APIs with minimal overhead, offering PSR-7 HTTP message support and a fast middleware-based architecture.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Slim PHP Framework
Direct install command
npx -y tokrepo@latest install b79ff53e-7568-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

Slim is a PHP micro framework designed for building APIs and small-to-medium web applications. It implements PSR-7 HTTP messages and PSR-15 middleware, giving developers a thin but standards-compliant layer between an HTTP request and response without the overhead of a full-stack framework.

What Slim Does

  • Routes HTTP requests to callable handlers using a fast, tree-based router
  • Implements PSR-7 request/response interfaces for interoperable HTTP handling
  • Supports a middleware pipeline for cross-cutting concerns like auth and CORS
  • Provides dependency injection via any PSR-11 compatible container
  • Handles error rendering with customizable error handlers and formatters

Architecture Overview

Slim's core is a dispatcher that wraps a PSR-7 request through a middleware stack, matches the URI against registered routes, invokes the matched callable, and returns the PSR-7 response. The framework has no ORM, templating engine, or built-in auth — those are added via Composer packages, keeping the core under 70 KB.

Self-Hosting & Configuration

  • Requires PHP 8.1+ and Composer
  • Install with composer require slim/slim plus a PSR-7 implementation
  • Entry point is typically public/index.php behind Apache or Nginx
  • Configure via PHP arrays or a PSR-11 container; no YAML or INI files needed
  • Deploy to any PHP-capable host, Docker, or serverless (AWS Lambda via Bref)

Key Features

  • PSR-7 and PSR-15 compliance ensures interoperability with the PHP ecosystem
  • Minimal footprint keeps startup time and memory usage low
  • Flexible middleware architecture for layering functionality
  • Route groups with shared middleware for clean API versioning
  • Built-in support for content negotiation and response formatting

Comparison with Similar Tools

  • Laravel — full-stack with ORM, queues, and auth; Slim is minimal and bring-your-own
  • Symfony — enterprise component library; Slim is a single micro framework
  • Lumen — Laravel-flavored micro framework; Slim is framework-agnostic and PSR-first
  • CodeIgniter — lightweight but opinionated MVC; Slim has no view layer
  • Mezzio (Laminas) — PSR-15 micro framework; Slim offers simpler API with less configuration

FAQ

Q: Is Slim suitable for large applications? A: Slim can power large apps when combined with a container, ORM, and templating engine, but a full-stack framework may be more productive at scale.

Q: How do I add templating? A: Install a renderer like slim/twig-view or slim/php-view and register it in the container.

Q: Does Slim support WebSockets? A: Not natively. Slim handles HTTP request-response cycles; use Ratchet or Swoole for WebSockets.

Q: What changed in Slim 4? A: Slim 4 decoupled the PSR-7 implementation, adopted PSR-15 middleware, and requires an explicit PSR-11 container.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets