PHPackages                             samaphp/microapp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. samaphp/microapp

ActiveLibrary[Framework](/categories/framework)

samaphp/microapp
================

A minimal PHP microframework router.

0.10.2(11mo ago)1171[7 issues](https://github.com/samaphp/microapp/issues)[1 PRs](https://github.com/samaphp/microapp/pulls)1MITPHPPHP &gt;=7.4

Since Apr 23Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/samaphp/microapp)[ Packagist](https://packagist.org/packages/samaphp/microapp)[ RSS](/packages/samaphp-microapp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (19)Used By (1)

microapp
========

[](#microapp)

MicroApp is a minimal PHP 7.4+ microframework for building super-microservices with clean routing and zero dependencies. Perfect for fast bootstraps, tiny APIs, internal tools, or focused endpoints where simplicity wins. Designed for developers who value clarity, control, zero framework overhead and long-term maintainability. Built for microservices that can live for decades without requiring upgrades or major refactors. You’re encouraged to follow future-proof design principles when building on top of it.

🌟 Features
----------

[](#-features)

- ✅ `GET`, `POST`, `PUT`, `DELETE`, and `PATCH` method support
- ✅ Named route parameters like `/user/{id}`
- ✅ JSON response helper via `$app->jsonResponse()`
- ✅ Centralized response lifecycle with override support
- ✅ PSR-4 structure with Composer autoloading
- ✅ Simple and readable one-file implementation
- ✅ Ready to be used as a Composer package
- ✅ Auto-discovery of controller classes with route definitions inside the class itself
- ✅ Optional CLI available via the `microapp-dev` package
- ✅ Middleware (before/after) for logging, authentication, CSRF protection, and other cross-cutting concerns

🚀 Getting Started
-----------------

[](#-getting-started)

- Install via Composer: `composer require samaphp/microapp`
- You can set things up manually (see sections below) or automate it using the `microapp-dev` package from the Developer Tools section.

🛠️ Developer Tools
------------------

[](#️-developer-tools)

Looking to scaffold `.htaccess`, `index.php`, or generate controllers?
Use the official companion package:
➡️ [`samaphp/microapp-dev`](https://github.com/samaphp/microapp-dev)

🔀 basePath Support
------------------

[](#-basepath-support)

If your application is served from a subdirectory (e.g., example.com/myapp/), you can pass the base path to MicroApp during initialization:

```
$app = new MicroApp('/myapp');

```

This ensures all routes are matched correctly regardless of where your app is hosted.

```
📌 You must also update your .htaccess rewrite rule to reflect the same subdirectory.

```

🟦 .htaccess example
-------------------

[](#-htaccess-example)

```

  RewriteEngine On

  # Enable this to support subdirectory installations after injecting basePath value to MicroApp('basePathHere')
  #RewriteBase /basePathHere/

  # Redirect everything except existing files and directories to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [QSA,L]

```

🟦 index.php Example
-------------------

[](#-indexphp-example)

The auto generated `index.php` will be like this:

```
