PHPackages                             rocboss/batio - 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. [API Development](/categories/api)
4. /
5. rocboss/batio

ActiveProject[API Development](/categories/api)

rocboss/batio
=============

A fast and extensible micro-framework for PHP to build RESTful API.

1.1.0(7y ago)91374MITPHPPHP ^7.0

Since Nov 2Pushed 7y ago2 watchersCompare

[ Source](https://github.com/rocboss/batio)[ Packagist](https://packagist.org/packages/rocboss/batio)[ Docs](https://github.com/rocboss/batio)[ RSS](/packages/rocboss-batio/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (10)Versions (13)Used By (0)

Batio
=====

[](#batio)

[![Build Status](https://camo.githubusercontent.com/4d9fe940c9fb6d0f1ecfcb6e547aab245ae93dc13952684869ee958bef30226b/68747470733a2f2f7777772e7472617669732d63692e6f72672f726f63626f73732f626174696f2e7376673f6272616e63683d6d6173746572)](https://www.travis-ci.org/rocboss/batio)[![Branch master](https://camo.githubusercontent.com/d13ff590538bd288fc9f75cbfe383af4eaaaa0c356f9e90aed2263bb322bd87f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6272616e63682d6d61737465722d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d13ff590538bd288fc9f75cbfe383af4eaaaa0c356f9e90aed2263bb322bd87f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6272616e63682d6d61737465722d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)[![Latest Stable Version](https://camo.githubusercontent.com/8e76282f470d193e4997598200beafa51d1d88ad5136c84828b9324a2bdc594d/68747470733a2f2f706f7365722e707567782e6f72672f726f63626f73732f626174696f2f762f737461626c652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/rocboss/batio)[![Latest Unstable Version](https://camo.githubusercontent.com/4f9ad28df5d25f9e85cc909c37144fdacc95383fbc4a6c5fa902b6038ee57752/68747470733a2f2f706f7365722e707567782e6f72672f726f63626f73732f626174696f2f762f756e737461626c652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/rocboss/batio)[![License](https://camo.githubusercontent.com/923a4d4f1b5827d07c90d73fcfd594f703ebe05f01339defab909520f9d665d6/68747470733a2f2f706f7365722e707567782e6f72672f726f63626f73732f626174696f2f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/rocboss/batio)

English | [简体中文](./README_zh-CN.md)

> A fast and extensible micro-framework for PHP to build RESTful API.

1. Install
----------

[](#1-install)

```
// (Recommend) If you’re using Composer, you can run the following command:
composer create-project --prefer-dist rocboss/batio batio
```

```
// Or git clone
git clone https://github.com/rocboss/batio.git batio
```

```
cd batio

cp .env.example .env
// Edit .env file
vim .env

composer install
chmod -R 755 app/storage

php -S 127.0.0.1:8888 -t public
```

Enter `http://127.0.0.1:8888` in the browser's address bar. If everything is correct, you can get the following return:

```
{
  "code": 0,
  "msg": "success",
  "data": "version: Batio 1.0.0"
}
```

> Note: the initial installation needs to edit the related configuration information in the `.env` file under the project root, and you can also extend the other configuration in the file according to specific requirements.

2. Framework
------------

[](#2-framework)

### 2.1 Router

[](#21-router)

In `app\config\routes.php`, you can customize API routes.

```
route('GET /', ['api\HomeController', 'index']);
```

> This is an ordinary route. When you visit the home page, you directly map to the `api\HomeController` controller, execute the following `index` method, and note that the type of controller method needs to be `protected`.

### 2.2 Middlewares

[](#22-middlewares)

In `app\config\app.php`, you can customize `Middleware` for routes, such as authorization authentication, user roles control, etc.

```
// Middlewares
'middlewares' => [
    'auth' => AuthMiddleware::class,
],
```

`Batio` encapsulates a simple authentication model based on JWT, just call the `auth()` method after the routing of the authentication API.

```
route('GET /', ['api\HomeController', 'user'])->auth();
```

The example

```
// Fail
{
    "code": 401,
    "msg": "[401 Unauthorized]."
}

// Success
{
    "code": 0,
    "msg": "success",
    "data": {
        "uid": 1,
        "user_name": "Jack",
        "user_age": 18
    }
}
```

> When you send a request, pass the `X-Authorization` of `JWT` value to the server in `header`.

```
// This method can be used to obtain JWT.
\Auth::getToken($uid);
```

### 2.3 Cache

[](#23-cache)

```
if (app()->cache('data')->contains('foo')) {
    $unit = app()->cache('data')->fetch('foo');
} else {
    $bar = 'bar cache';
    app()->cache('data')->save('foo', $bar);
}
```

### 2.4 Log

[](#24-log)

```
$logger = app()->log()->debug('debug log');
```

### 2.5 Database &amp; Models

[](#25-database--models)

```
$userModel = new UserModel();
$userModel->name = 'Jack';
$userModel->email = 'bar@foo.com';
$userModel->avatar = 'https://foo.com/xxxxxx.png';
$userModel->password = password_hash("mypassword", PASSWORD_DEFAULT);
$userModel->save();
```

> In `app\models`, `model` and `service` are stored, `model` is mainly dealing with database. The official recommended practice is that `service` calls `model`, `controller` calls `service`, so that the design makes the layering more reasonable, and the functional modules are decoupled to facilitate the business system.

### Mainly depended on

[](#mainly-depended-on)

```
lcobucci/jwt: 3.2.*
mikecao/flight: 1.3.*
aryelgois/medools: 5.0
catfan/medoo: 1.5.*
monolog/monolog: 1.23.*
doctrine/cache: 1.4.*
vlucas/phpdotenv: 2.0.*
predis/predis: 1.1.*
ruflin/elastica: 6.1.*
elasticsearch/elasticsearch: 6.0.*

```

`Batio` uses some excellent third party components, and you can get specific documents from their websites.

Authorization agreement
-----------------------

[](#authorization-agreement)

[MIT Agreement](http://opensource.org/licenses/MIT)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Every ~42 days

Recently: every ~66 days

Total

11

Last Release

2688d ago

Major Versions

0.2.4 → 1.0.02018-07-05

PHP version history (2 changes)0.1.0PHP &gt;=5.5.9

0.2.1PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/70c6255047b7fe853ef11b676b38aa492bffdb43c80ca6296c9fe2aaec525c74?d=identicon)[rocboss](/maintainers/rocboss)

---

Top Contributors

[![rocboss](https://avatars.githubusercontent.com/u/11001145?v=4)](https://github.com/rocboss "rocboss (31 commits)")

---

Tags

batiobatio-frameworkphprestful-api

### Embed Badge

![Health badge](/badges/rocboss-batio/health.svg)

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

###  Alternatives

[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[concrete5/core

Concrete core subtree split

19159.3k48](/packages/concrete5-core)[lion/bundle

Lion-framework configuration and initialization package

122.2k1](/packages/lion-bundle)

PHPackages © 2026

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