Configs2026年7月1日·1 分钟阅读

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 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Slim PHP Framework
直接安装命令
npx -y tokrepo@latest install b79ff53e-7568-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产