psvneo / typo3-extension-easy-api
This extension adds an easy way to provide custom API endpoints for your extensions.
1.0.0
2025-04-14 14:46 UTC
Requires
- php: ^8.2
- typo3/cms-backend: ^13.4
- typo3/cms-core: ^13.4
- typo3/cms-extbase: ^13.4
- typo3/cms-fluid: ^13.4
- typo3/cms-frontend: ^13.4
- typo3/cms-lowlevel: ^13.4
Requires (Dev)
- armin/editorconfig-cli: ^2.1
- michielroos/typo3scan: ^1.7
- psvneo/qa-toolset-t3: ^3.0
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
]);
}
}