tripomatic/nette-api
Composer 安装命令:
composer require tripomatic/nette-api
包简介
Build REST APIs with Nette Framework
README 文档
README
Build REST APIs with Nette Framework.
Tripomatic\NetteApi is a very light base for building REST APIs with Nette Framework. It provides an extremely minimalist base presenter, an error presenter that ensures returning a valid JSON on any error and takes care of logging, and a handy JSON prettifier for testing APIs in browser that does not force you to hide your Tracy panel.
Installation
Install Tripomatic\NetteApi using Composer:
$ composer require tripomatic/nette-api
Quickstart
Add Tripomatic\NetteApi extension in your NEON config:
extensions: api: Tripomatic\NetteApi\DI\ApiExtension
Create your first RESTful presenter inherited from minimalist Tripomatic\NetteApi\Application\Presenter:
use Nette\Application\Request; use Tripomatic\NetteApi\Application\Presenter; use Tripomatic\NetteApi\Application\Responses\JsonResponse; class WeatherPresenter extends Presenter { public function get(Request $request) { $city = $request->getParameter('city'); $data = ...; // get weather data for the city return new JsonResponse($data); } // implement ohter REST methods similarly }
Configuration
Tripomatic\NetteApi does not require any additional configuration, it sets up two handy defaults:
- An error presenter is set up that ensures the API returns a valid JSON in all error situations.
- API responses are prettified by default when running in debug mode, Tracy panel is also visible.
This behavior can be easily overridden in corresponding extension's section:
api: prettify: %debugMode% # can be set to TRUE/FALSE errorPresenter: NetteApi:Error mapping: NetteApi: 'Tripomatic\NetteApi\Application\Presenters\*Presenter'
Bootsraping
If you need some help with writing your application bootsrap here is an example that we use in Tripomatic:
require __DIR__ . '/../vendor/autoload.php'; $tomDebug = getenv('TOM_DEBUG') === 'TRUE' && isset($_COOKIE['tom_api_debug']); $tomLogDir = getenv('TOM_LOG_DIR') ?: '/var/log/tripomatic/some-api'; $tomTmpDir = getenv('TOM_TMP_DIR') ?: '/var/tmp/some-api'; $tomConfigFile = getenv('TOM_CONFIG_FILE') ?: __DIR__ . '/../config/config.local.neon'; $configurator = new Nette\Configurator; $configurator->setDebugMode($tomDebug); $configurator->enableDebugger($tomLogDir); $configurator->setTempDirectory($tomTmpDir); $configurator->addConfig(__DIR__ . '/../config/config.neon'); if (file_exists($tomConfigFile)) { $configurator->addConfig($tomConfigFile); } return $configurator->createContainer();
Yes, with Nette Framework it can really be that minimalist. Everything else can be achieved with Nette's great Dependency Injection implementation. For more details see Nette Framework documentation.
License
Tripomatic\NetteApi is licensed under MIT.
tripomatic/nette-api 适用场景与选型建议
tripomatic/nette-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.17k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「nette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tripomatic/nette-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tripomatic/nette-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tripomatic/nette-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Nette Framework adapter for I18n package
Build forms from schema
Asynchronous MQTT client built on React
Form with datetime support and Bootstrap 4 form renderer
统计信息
- 总下载量: 3.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 7
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-25