sgalinski / sg-apicore
Modern API Core for TYPO3 - Modern, performance-driven TYPO3 API framework with attribute-based routing and endpoint metadata, multi-API/multi-version setup, tenant-aware request context, OpenAPI 3 generation with Swagger UI and CLI export, MCP/Model Context Protocol tool exposure over JSON-RPC and
Package info
gitlab.sgalinski.de/typo3/sg_apicore.git
Type:typo3-cms-extension
pkg:composer/sgalinski/sg-apicore
Requires
- php: >=8.2.0
- nikic/fast-route: ^1.3
- typo3/cms-backend: >=12.3.0 <=14.3.99
- typo3/cms-core: >=12.3.0 <=14.3.99
- typo3/cms-extbase: >=12.3.0 <=14.3.99
- typo3/cms-frontend: >=12.3.0 <=14.3.99
- typo3/cms-scheduler: >=12.3.0 <=14.3.99
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
- sgalinski/sg_apicore: 3.2.0
- dev-master
- 3.2.0
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.0
- v2.x-dev
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- v1.x-dev
- 1.24.1
- 1.24.0
- 1.23.1
- 1.23.0
- 1.22.0
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.3
- 1.18.2
- 1.18.1
- 1.18.0
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.3
- 1.16.2
- 1.16.1
- 1.16.0
- 1.15.1
- 1.15.0
- 1.14.2
- 1.14.1
- 1.14.0
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.5
- 1.11.4
- 1.11.3
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
This package is auto-updated.
Last update: 2026-11-24 11:51:54 UTC
README
License: GNU GPL, Version 2
Repository: https://gitlab.sgalinski.de/typo3/sg_apicore
Please report bugs here: https://gitlab.sgalinski.de/typo3/sg_apicore/-/issues
Short Summary
Provides an API framework for TYPO3: Multi-API, Multi-Tenants, Attribute-based endpoint configuration, Logging, Token JWT Bearer auth, User auth, Entity CRUD registration, Custom Endpoints.
For detailed information, please refer to the Documentation in docs/. For website-ready end-user communication, see End-User-Documentation.
Installation
The extension requires PHP 8.2 or newer and supports TYPO3 12.3 through TYPO3 14.3.
Install the extension via composer:
composer require sgalinski/sg-apicoreActivate the extension in the TYPO3 Extension Manager.
Quick Start (3 Steps)
1. Register your Controller
Add your controller to Configuration/Services.php and tag it with sg_apicore.router:
$services->set(MyController::class)
->tag('sg_apicore.router');
2. Define an Endpoint
Use the #[ApiRoute] attribute in your controller action:
#[ApiRoute(path: '/hello', methods: ['GET'])]
public function helloAction(ServerRequestInterface $request): ResponseInterface {
return $this->responseService->createSuccessResponse(['message' => 'Hello!']);
}
3. Access the API
Open your browser at https://your-domain.local/api/public/v1/docs/ui to see the generated Swagger UI and test your new
endpoint!
Testing
You can test the API by calling the health endpoint:
# Basic health check
curl https://your-project.local/api/health
# API-specific health check (if registered)
curl https://your-project.local/api/public/v1/health
The API path prefix is configurable via the extension configuration (default: /api/).
API Registration
To register a new API, you use the ApiRegistry service. Detailed configuration options can be found in
the APIs & Registration Documentation.
use SGalinski\SgApiCore\Service\ApiRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
$apiRegistry = GeneralUtility::makeInstance(ApiRegistry::class);
$apiRegistry->registerApi('public', ['1']);
Writing Endpoints
Endpoints are defined using PHP attributes on controller methods. See Writing Endpoints for a full guide. For a complete template with current best practices, see ExampleController.
#[ApiRoute(path: '/my-endpoint', methods: ['GET'], apiId: 'public', version: '1')]
public function myAction(ServerRequestInterface $request): ResponseInterface {
return $this->responseService->createSuccessResponse(['message' => 'Hello World']);
}
Standardized Responses
The ResponseService provides a unified way to create JSON responses, using RFC 9457 Problem Details for errors.
RFC 9457 supersedes RFC 7807; the existing application/problem+json response format is unchanged.
See Writing Endpoints - Responses.
Fluid URLs and uploads
Use <api:uri.api path="/my-endpoint" /> in Fluid templates to create site- and language-aware API URLs. File-only
endpoints can declare #[ApiBodyParam(name: 'file', type: 'file')] and receive a multipart upload without requiring
a JSON body. Use ResponseService::createDownloadResponse() for streamed download responses.
Pagination
The extension provides a PaginationService to handle consistent pagination across endpoints.
See Writing Endpoints - Pagination (Note: Add pagination details to docs if
missing).
TCA Mapper
The TcaMapper service allows you to map TYPO3 database records to API response arrays based on the TCA.
See TCA Mapper Documentation.
Database Schema
Rate-limit storage is represented in TCA, but ext_tables.sql remains required for its unique index and for compatibility with existing installations. Do not remove it until the schema comparison has been verified for every supported TYPO3 version.
Auto-CRUD Resources
You can expose TYPO3 tables as API resources with full CRUD support. See Auto-CRUD Resources Documentation.
OpenAPI Documentation
The extension automatically generates OpenAPI 3.0 specifications. You can access Swagger UI at
/api/{apiId}/v{version}/docs/ui. See OpenAPI Documentation.
MCP Integration
The extension can expose endpoints as MCP tools through a JSON-RPC endpoint:
POST /api/{apiId}/v{version}/mcpGET /api/{apiId}/v{version}/mcpfor the optional Streamable HTTP SSE channel
Use api:mcp:list to see the effective tool exposure after configuration, denylist, and endpoint-level exclusions.
See MCP Documentation.
Backend Module
The extension provides a TYPO3 Backend Module under System > API Core.
- APIs & Versions: Overview and Swagger UI links.
- Token Management: Create and manage Opaque and Refresh tokens.
- Supports optional FE-user bound tokens (
user_idmapped tofe_users) for per-user API key flows. - Token list keeps current filter state while editing/revoking/regenerating.
- Supports optional FE-user bound tokens (
- Endpoints: List of all registered endpoints and their requirements, including effective MCP exposure (tool names, attribute-based exclusions, and API/version mapping).
See Authentication & Scopes - Backend for details.
Logging
Comprehensive logging for API requests and responses, including request tracking via a unique Request ID. See Logging Documentation.
Multi-Tenancy
Every API request runs in a TenantContext, usually derived from the TYPO3 Site. Endpoints can be filtered by
tenants using the tenants property in the #[ApiRoute] attribute.
See Tenants Documentation.
Security & Authentication
Supports multiple auth modes (public, token, user, backend) and scope-based authorization.
#[RequireUser] accepts an existing TYPO3 frontend-user session for public browser API routes.
- API Level: Define the default
authModeas a string in theApiRegistry. - Endpoint Level: Override or extend the
authModeusing the#[ApiRoute]attribute (supports string or array, e.g.,['public', 'user']).
CORS
CORS handling is provided by ApiCorsMiddleware and is enabled for API paths (apiPathPrefix) by default.
- Origin policy is default deny.
- Preflight requests (
OPTIONSwithAccess-Control-Request-Method) are answered directly. - Allowed origins are configured per API via
ApiRegistry::registerApi(..., $security):
$apiRegistry->registerApi('partner', ['1'], [
'authMode' => 'user',
'authProviders' => ['beareropaquetokenprovider'],
'cors' => [
'allowedOrigins' => ['https://app.example.org'],
'allowCredentials' => true,
],
]);
Known Issues & Troubleshooting
Missing Authorization Header (Apache)
In some hosting environments (especially Apache with PHP via CGI/FastCGI), the Authorization header is stripped before it reaches PHP. If you experience "Authentication required" errors despite sending a valid token, add the following to your .htaccess file:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
The extension includes a fallback to check for HTTP_AUTHORIZATION and REDIRECT_HTTP_AUTHORIZATION, but this server-side configuration is the most reliable fix.
Legacy Support (Migration from sg_rest)
The extension provides a bridge to support legacy sg_rest clients. This includes:
- Middleware for mapping old URL patterns.
- Support for
fe_usersauthentication tokens. - Emulation of the old response format.
Note: Legacy support is disabled by default. See the Migration Guide for details on how to enable and use it.
Architectural Decisions
Record-type read projection
Active field-type/relation/child-TCA overrides that cannot be resolved safely from a raw record retain the full authorized read. Expanded relations with parent-specific child types also retain full authorized child values. These fallbacks preserve the configured read allowlists; they do not implement a separate FormEngine or change the existing write mapping. Ordinary form presentation/default overrides do not expand field exposure.
TCA type-based response reduction is enabled by default for resources registered
with compactTcaRead: true. Set enableTcaTypeProjection to 0 to opt out
installation-wide. Existing typeProjection registrations keep their previous
response behavior.
An opted-in list/get response intersects authorized fields with the active TCA type.
fullRecord=true bypasses this presentation reduction, not API read-field restrictions or
Backend User authorization. Persisted post-write responses retain complete authorized
fields regardless of the switch, because verification may require fields outside showitem.
Writable schemas are unchanged. Disabling the setting restores full authorized reads;
refresh system/discovery/response caches when switching modes to avoid stale evidence.
Resources with preserveNullOnFullRecord: true accept includeNull=true alongside fullRecord=true.
This returns authorized database NULL values as JSON null, so verification can distinguish a known null from an absent
field. Missing raw keys remain absent. Ordinary reads and post-write responses keep
their existing null-omission behavior, including when type projection is disabled.
This option never restores fields excluded by the resource read policy.
Resources with strictReadAllowLists: true treat an explicitly configured per-table
allowed: [] as an empty field selection in either read mode.
Resources with requireBackendUserReadOwnership: true check native FAL source-file read access before
including relation metadata or public URLs, even when relation depth is zero or
fullRecord=true is requested. Unreadable files are omitted from expanded file
fields. A direct protected sys_file_reference read requires access to its source
file as well as its owner; a forbidden source produces 403. Unprotected APIs retain
their configured relation behavior. File checks initialize fresh user-scoped native
storage permissions so cached administrator storage cannot grant editor access.
Under the same policy, every expanded child record must pass the calling Backend User's direct record-read checks, including raw rows reused from the mapper cache. An unauthorized child fails the protected expanded response; fullRecord does not bypass this boundary. APIs without a Backend User context retain their existing mapping behavior. Additional child ACL work applies only when relations are expanded.
For information on why we chose certain technologies and patterns, see our Architectural Decision Records at docs/adr/.
Backend advertisements
Advertisement data, the ViewHelper, JavaScript and their tests are synchronized from sgc-scripts.
Edit the central sources and run sgc syncBackendAdvertisements sg-apicore to update them.
Campaigns for loaded TYPO3 extensions are excluded; no notice is shown when none remain eligible.
The backend notice promotes related sgalinski extensions. Dismissing it hides notices from this extension for three days
in the same browser, across tabs and logins, using localStorage. The duration defaults to
DEFAULT_DISMISS_FOR_SECONDS in the advertisement script; a positive dismissForSeconds partial argument overrides it.