psvneo/typo3-extension-easy-api
Composer 安装命令:
composer require psvneo/typo3-extension-easy-api
包简介
This extension adds an easy way to provide custom API endpoints for your extensions.
关键字:
README 文档
README
This extension adds an easy way to provide custom API endpoints for your extensions.
Requirements
- PHP
^8.2. - TYPO3
14.1
Documentation
This extension is a fork of the extension app_routes. It provides a simple way to create custom API endpoints in TYPO3.
Under the hood, it uses Symfonys Routing Component. to resolve the routes.
How to set up a new API endpoint
There are two ways to register API endpoints:
- PHP Attribute Method - For global endpoints available across all sites (or optionally restricted to a specific site)
- YAML Configuration Method - For site-specific endpoints (automatically restricted to the site that defines them)
Method 1: PHP Attribute (Global Endpoints)
To create a global API endpoint, create a class that implements the \Psr\Http\Server\RequestHandlerInterface and use the \PSVNEO\PsvneoEasyApi\Attribute\AsEndpoint attribute to define the
endpoint's properties.
| Property | Description | Default Value | Example Value |
|---|---|---|---|
name | A unique name for the endpoint, used to identify it in the system. | Required | dummy |
path | The path for the endpoint. | Required | /api/my-endpoint |
methods | The HTTP methods the endpoint should respond to. | All methods | ['GET'] |
defaults.cache | Indicates if the endpoint should be cached. Only available for GET and HEAD requests. | false | true |
defaults.tsfe | Specifies if the endpoint requires a loaded TypoScript Frontend (TSFE). | false | true |
namespace Vendor\MyExtensionName\Api;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use PSVNEO\PsvneoEasyApi\Attribute\AsEndpoint;
use TYPO3\CMS\Core\Http\JsonResponse;
#[AsEndpoint(
name: 'my-endpoint',
path: '/api/my-endpoint',
methods: ['GET'],
defaults: [
'cache' => true,
'tsfe' => true,
]
)]
final class MyEndpoint implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
// Your custom logic here...
return new JsonResponse([
'success' => true
]);
}
}
Method 2: YAML Configuration (Site-Specific Endpoints)
For site-specific endpoints, you can define them in a YAML configuration file and import it in your TYPO3 site configuration. This ensures the endpoint is only available for sites that include this definition.
Step 1: Create a YAML file in your extension (e.g., Configuration/EasyApi.yaml):
easyApiEndpoints:
my_api:
handler: Vendor\MyExtensionName\Api\MyEndpoint
name: my_api
path: /api/my-endpoint
methods:
- GET
- POST
defaults:
cache: true
tsfe: true
Step 2: Create the request handler class (without the AsEndpoint attribute):
namespace Vendor\MyExtensionName\Api;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\JsonResponse;
final class MyEndpoint implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
// Your custom logic here...
return new JsonResponse([
'success' => true
]);
}
}
Step 3: Import the YAML file in your site configuration (config/sites/<your-site>/config.yaml):
imports:
- resource: 'EXT:my_extension/Configuration/EasyApi.yaml'
Site-specific behavior: The endpoint will now only be available for the site that includes this configuration. If you try to access it from a different site, it will return a 404 error.
Important: Site config-based endpoints are registered during DI container compilation for optimal performance. After modifying endpoint configurations in site config YAML files, you must clear the TYPO3 cache to rebuild the container:
vendor/bin/typo3 cache:flush
This ensures your endpoint changes are picked up by the system.
psvneo/typo3-extension-easy-api 适用场景与选型建议
psvneo/typo3-extension-easy-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 486 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「typo3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 psvneo/typo3-extension-easy-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 psvneo/typo3-extension-easy-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 psvneo/typo3-extension-easy-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Set Links with a specific language parameter
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
统计信息
- 总下载量: 486
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-04-14