{"id":24469180,"url":"https://github.com/rocboss/batio","last_synced_at":"2025-04-13T10:24:25.004Z","repository":{"id":62536655,"uuid":"108667143","full_name":"rocboss/batio","owner":"rocboss","description":"A fast and extensible micro-framework for PHP to build RESTful API.","archived":false,"fork":false,"pushed_at":"2019-01-04T07:31:38.000Z","size":52,"stargazers_count":90,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T01:47:50.309Z","etag":null,"topics":["batio","batio-framework","php","restful-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocboss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-28T16:54:44.000Z","updated_at":"2025-03-01T07:42:21.000Z","dependencies_parsed_at":"2022-11-02T15:31:55.090Z","dependency_job_id":null,"html_url":"https://github.com/rocboss/batio","commit_stats":null,"previous_names":[],"tags_count":11,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocboss%2Fbatio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocboss%2Fbatio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocboss%2Fbatio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocboss%2Fbatio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocboss","download_url":"https://codeload.github.com/rocboss/batio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248696704,"owners_count":21147164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batio","batio-framework","php","restful-api"],"created_at":"2025-01-21T07:14:40.348Z","updated_at":"2025-04-13T10:24:24.962Z","avatar_url":"https://github.com/rocboss.png","language":"PHP","readme":"# Batio\n[![Build Status](https://www.travis-ci.org/rocboss/batio.svg?branch=master)](https://www.travis-ci.org/rocboss/batio)\n![Branch master](https://img.shields.io/badge/branch-master-brightgreen.svg?style=flat-square)\n[![Latest Stable Version](https://poser.pugx.org/rocboss/batio/v/stable.svg?format=flat-square)](https://packagist.org/packages/rocboss/batio)\n[![Latest Unstable Version](https://poser.pugx.org/rocboss/batio/v/unstable.svg?format=flat-square)](https://packagist.org/packages/rocboss/batio)\n[![License](https://poser.pugx.org/rocboss/batio/license?format=flat-square)](https://packagist.org/packages/rocboss/batio)\n\nEnglish | [简体中文](./README_zh-CN.md)\n\n\u003e   A fast and extensible micro-framework for PHP to build RESTful API.\n\n## 1. Install\n\n```bash\n// (Recommend) If you’re using Composer, you can run the following command:\ncomposer create-project --prefer-dist rocboss/batio batio\n```\n\n```bash\n// Or git clone\ngit clone https://github.com/rocboss/batio.git batio\n```\n\n```bash\ncd batio\n\ncp .env.example .env\n// Edit .env file\nvim .env\n\ncomposer install\nchmod -R 755 app/storage\n\nphp -S 127.0.0.1:8888 -t public\n```\nEnter `http://127.0.0.1:8888` in the browser's address bar. If everything is correct, you can get the following return:\n\n```json\n{\n  \"code\": 0,\n  \"msg\": \"success\",\n  \"data\": \"version: Batio 1.0.0\"\n}\n```\n\n\u003e 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.\n\n\n## 2. Framework\n\n### 2.1 Router\nIn `app\\config\\routes.php`, you can customize API routes.\n\n```php\nroute('GET /', ['api\\HomeController', 'index']);\n```\n\n\u003e 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`.\n\n\n### 2.2 Middlewares\n\nIn `app\\config\\app.php`, you can customize `Middleware` for routes, such as authorization authentication, user roles control, etc.\n\n```php\n// Middlewares\n'middlewares' =\u003e [\n    'auth' =\u003e AuthMiddleware::class,\n],\n```\n\n`Batio` encapsulates a simple authentication model based on JWT, just call the `auth()` method after the routing of the authentication API.\n\n```php\nroute('GET /', ['api\\HomeController', 'user'])-\u003eauth();\n```\n\nThe example\n\n```json\n// Fail\n{\n    \"code\": 401,\n    \"msg\": \"[401 Unauthorized].\"\n}\n\n// Success\n{\n    \"code\": 0,\n    \"msg\": \"success\",\n    \"data\": {\n        \"uid\": 1,\n        \"user_name\": \"Jack\",\n        \"user_age\": 18\n    }\n}\n```\n\n\u003e When you send a request, pass the `X-Authorization` of `JWT` value to the server in `header`.\n\n```php\n// This method can be used to obtain JWT.\n\\Auth::getToken($uid);\n```\n\n### 2.3 Cache\n\n```php\nif (app()-\u003ecache('data')-\u003econtains('foo')) {\n    $unit = app()-\u003ecache('data')-\u003efetch('foo');\n} else {\n    $bar = 'bar cache';\n    app()-\u003ecache('data')-\u003esave('foo', $bar);\n}\n```\n\n### 2.4 Log\n\n```php\n$logger = app()-\u003elog()-\u003edebug('debug log');\n```\n\n\n### 2.5 Database \u0026 Models\n\n```php\n$userModel = new UserModel();\n$userModel-\u003ename = 'Jack';\n$userModel-\u003eemail = 'bar@foo.com';\n$userModel-\u003eavatar = 'https://foo.com/xxxxxx.png';\n$userModel-\u003epassword = password_hash(\"mypassword\", PASSWORD_DEFAULT);\n$userModel-\u003esave();\n```\n\n\u003e 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. \n\n### Mainly depended on\n```\nlcobucci/jwt: 3.2.*\nmikecao/flight: 1.3.*\naryelgois/medools: 5.0\ncatfan/medoo: 1.5.*\nmonolog/monolog: 1.23.*\ndoctrine/cache: 1.4.*\nvlucas/phpdotenv: 2.0.*\npredis/predis: 1.1.*\nruflin/elastica: 6.1.*\nelasticsearch/elasticsearch: 6.0.*\n```\n\n`Batio` uses some excellent third party components, and you can get specific documents from their websites.\n\n\n## Authorization agreement\n\n [MIT Agreement](http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocboss%2Fbatio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocboss%2Fbatio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocboss%2Fbatio/lists"}