psvneo/typo3-extension-easy-api

This extension adds an easy way to provide custom API endpoints for your extensions.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:typo3-cms-extension

1.0.0 2025-04-14 14:46 UTC

This package is auto-updated.

Last update: 2025-04-14 14:51:22 UTC


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.

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
defaults.siteIdentifierIf set the api endpoint is only available for the defined site identifier.Defined by the base urlmy-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
        ]);
    }
}