psvneo/typo3-extension-easy-api
最新稳定版本:1.0.0
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
13.4
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
To create a new API endpoint, you need to 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 |
defaults.siteIdentifier | If set the api endpoint is only available for the defined site identifier. | Defined by the base url | my-site |
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: 'dummy',
path: '/api/my-endpoint',
methods: ['GET'],
defaults: [
'cache' => true,
'tsfe' => true,
'siteIdentifier' => 'my-site',
]
)]
final class MyEndpoint implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
// Your custom logic here...
return new JsonResponse([
'success' => true
]);
}
}
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-04-14