psvneo/typo3-extension-easy-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  1. PHP Attribute Method - For global endpoints available across all sites (or optionally restricted to a specific site)
  2. 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.

PropertyDescriptionDefault ValueExample Value
nameA unique name for the endpoint, used to identify it in the system.Requireddummy
pathThe path for the endpoint.Required/api/my-endpoint
methodsThe HTTP methods the endpoint should respond to.All methods['GET']
defaults.cacheIndicates if the endpoint should be cached. Only available for GET and HEAD requests.falsetrue
defaults.tsfeSpecifies if the endpoint requires a loaded TypoScript Frontend (TSFE).falsetrue
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 我们能提供哪些服务?
定制开发 / 二次开发

基于 psvneo/typo3-extension-easy-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 486
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-04-14