PHPackages                             tomlerendu/microapi - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. tomlerendu/microapi

ActiveFramework[HTTP &amp; Networking](/categories/http)

tomlerendu/microapi
===================

An extremely lightweight PHP framework for creating APIs

1.1.0(11y ago)120[1 issues](https://github.com/tomlerendu/MicroAPI/issues)PHPPHP &gt;=5.4.0

Since Jan 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tomlerendu/MicroAPI)[ Packagist](https://packagist.org/packages/tomlerendu/microapi)[ RSS](/packages/tomlerendu-microapi/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

MicroAPI
========

[](#microapi)

MicroAPI is an extremely lightweight PHP framework for creating REST APIs.

Requirements
------------

[](#requirements)

- Apache 2.0+
    - mod\_rewrite enabled
- PHP 5.4+

Downloading and Installing
--------------------------

[](#downloading-and-installing)

Structure
---------

[](#structure)

### File system

[](#file-system)

A MicroAPI application by default has the following structure.

- App
    - Controller
    - Models
    - Services
- MicroAPI
- public

The directory structure can be changed by editing the constants `MICROAPI_PATH` and `APP_PATH` in `public/const.php` then moving the directories to their corresponding locations. It is advisable to keep application code out of the public directory.

The App directory is where you write your application.

The MicroAPI directory contains the framework. If there are multiple websites using MicroAPI on the same system they can be configured to share one copy of it.

The public directory is where the requests enter the framework.

### Namespaces and autoloading

[](#namespaces-and-autoloading)

MicroAPI follows the PSR-4 standard for autoloading classes.

### Request response cycle

[](#request-response-cycle)

Within the App directory there are three files

1. App/config.php function is executed
2. App/run.php function is executed
3. App/routes.php function is executed - If a route is matched its controller is executed

Config
------

[](#config)

Configuration variables for the application can be defined in App/config.php. By default there are options for the database and response already listed. It's recommended not to define values that have a key starting with `microapi.`.

Routing
-------

[](#routing)

Routes for your application are defined in the `app/routes.php` file. The router will initialise the controller for the first match, once a match has been found the rest of the routes will not be checked.

By default the `app/routes.php` has two sample routes showing how to setup a function and a class.

```
return function($router)
{

    $router->get([
        'route' => '/name/(name)',
        'class' => 'Example@getName',
        'require' => function() {
            return 1 + 1 == 2;
        }
    ]);

    $router->post([
        'route' => '/name/(name)',
        'function' => 'functionExample@postName',
    ]);

};
```

#### Methods

[](#methods)

The router has the methods `get`, `post`, `put`, `delete` which match the corresponding HTTP methods and `any` which will match any HTTP method.

#### Routes and wildcards

[](#routes-and-wildcards)

#### Extra requirements

[](#extra-requirements)

The require function allows for any additional requirements to be specified before the route is matched. If anything other than true is returned from the function the route will not be matched.

```
$router->get([
    'route' => '/user/(id)',
    'function' => 'user@details',
    'require' => function($database, $request) {
        $user = $database->select('SELECT id FROM User WHERE id = ?', $request->getPathWildcard('id'));
        return count($user) === 1;
    }
]);
```

Controllers
-----------

[](#controllers)

Controllers are dependency injected, they can be either a function or a method on an object.

```
function myController($request, $response, $database)
{
    $id = $request->getParam('id');
    $results = $database->select('SELECT * FROM Table WHERE id = ?', $id);

    $response->make($results);
}
```

Services
--------

[](#services)

A service is an object that can be injected at various places in the application, there will only one instance of each service per request. By default MicroAPI comes with six services.

### Request

[](#request)

The request object is a representation of the request the user made.

### Responses

[](#responses)

Responses are "replies" to a clients request, only one response should be sent per request.

### Database

[](#database)

The database service is built on top of PDO, it has four convenience functions to make accessing the database easier. For more specific tasks you can access the database directly by calling `getConnection()` which returns the PDO object.

### Injector

[](#injector)

### Autoloader

[](#autoloader)

### Config

[](#config-1)

### Creating a custom service

[](#creating-a-custom-service)

Models
------

[](#models)

Known issues
------------

[](#known-issues)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4201d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3859851?v=4)[Tom Lerendu](/maintainers/tomlerendu)[@tomlerendu](https://github.com/tomlerendu)

---

Top Contributors

[![tomlerendu](https://avatars.githubusercontent.com/u/3859851?v=4)](https://github.com/tomlerendu "tomlerendu (83 commits)")[![tomayoola](https://avatars.githubusercontent.com/u/25983410?v=4)](https://github.com/tomayoola "tomayoola (40 commits)")

---

Tags

apiautoloaderframeworkphprouterapirestinterfaceapplicationlightweightprogramming

### Embed Badge

![Health badge](/badges/tomlerendu-microapi/health.svg)

```
[![Health](https://phpackages.com/badges/tomlerendu-microapi/health.svg)](https://phpackages.com/packages/tomlerendu-microapi)
```

###  Alternatives

[aplus/mvc

Aplus Framework MVC Library

2621.6M3](/packages/aplus-mvc)[mediamonks/rest-api-bundle

MediaMonks Rest API Symfony Bundle

1656.2k1](/packages/mediamonks-rest-api-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
