robinscholz/better-rest
Composer 安装命令:
composer require robinscholz/better-rest
包简介
Kirby Plugin for better REST requests
关键字:
README 文档
README
A Kirby plugin that exposes the internal REST API at /rest with the option to convert Kirbytags to HTML and add a srcset to images in the process. Intended to convert Kirby into a headless CMS.
Disclaimer
While this plugin is still functional, quite a few alternatives exist for turning Kirby into a headless content management system. If you are looking for a more sophisticated and modern solution, please take a look at the Kirby Query Language plugin, the recent work of Johann Schopplich or Kirby Content Representations.
Usage
The API can be accessed at /rest. The plugin only allows GET requests.
Authentification
Requests need to be authenticated via Basic Auth. It’s recommended to create a seperate API User with either a custom blueprint or with the one provided by this plugin called better-rest API. Read more about user roles in the docs.
Basic Auth needs to be enabled in the site/config/config.php:
return [
'api' => [
'basicAuth' => true
]
];
Kirby 3 API
Examples:
rest/pages/:id: https://getkirby.com/docs/reference/api/pagesrest/site: https://getkirby.com/docs/reference/api/siterest/users/:id: https://getkirby.com/docs/reference/api/users
Better-Rest Settings from Query
All standard setting as well as settings defined in site/config/onfig.php can be overwritten on a per-request basis. Simply prefix the setting with br- and include it as a query.
Examples:
rest/pages/test?br-srcset=375,1200: br-srcsetrest/pages/test?br-smartypants=1: br-smartypantsrest/pages/test?br-language=fr: br-languagerest/pages/test?br-kirbytags=0&br-srcset=0: br-kirbytag br-srcset
Multilang
The plugin supports multiple language settings. To fetch content for a specific language include a X-Language header containing the desired language code with your request. Alternatively a br-language query can be used.
Settings
Config File
- The plugin converts kirbytags to HTML and adds a
srcsetto images by default. - Additionally it is possible to enable smartypants.
- To overwrite the default language it is possible to set a language code.
All settings need to be prefixed with robinscholz.better-rest.!
| Settings | Default | Options |
|---|---|---|
| kirbytags | true |
boolean |
| smartypants | false |
boolean |
| srcset | [375, 667, 1024, 1680] |
Array or false |
| language | null |
null or string |
Caveats
HTTPS
The Kirby installation needs to be served with a TLS Certicificate via https.
Local setup
For local development use Laravel Valet or disable https in the site/config/config.php:
return [ 'api' => [ 'basicAuth' => true, 'allowInsecure' => true ] ];
WARNING: Do not use this setting for production environments!
Installation
Download
Download and copy this repository to /site/plugins/better-rest.
Composer
composer require robinscholz/better-rest
Git submodule
git submodule add https://github.com/robinscholz/better-rest.git site/plugins/better-rest
Credits
A big thanks to @bnomei who refactored the initial source code into something extendable and future proof. If you are using this plugin please consider buying him a ☕!
License
MIT
robinscholz/better-rest 适用场景与选型建议
robinscholz/better-rest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 506 次下载、GitHub Stars 达 52, 最近一次更新时间为 2019 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「rest」 「api」 「cms」 「markdown」 「headless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robinscholz/better-rest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robinscholz/better-rest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robinscholz/better-rest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 506
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 52
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-04