Getting started 

What does it do 

T3api provides a configurable and customizable REST API for Extbase models. API resources, their operations, filters and access rules are configured with annotations on the model class (or on a class extending a model of another extension, see Integration), output of the models with annotations or YAML serializer metadata.

Most configuration options follow API Platform, so they are familiar to developers who know this framework.

Responses use JSON-LD and Hydra (partial support), which allows frontend applications to discover resources, filters and pagination from the responses.

Installation 

Supported versions:

TYPO3 PHP
12.4 8.1 - 8.4
13.4 8.2 - 8.5
14 8.2 - 8.5

Run

composer require sourcebroker/t3api
Copied!

Configuration 

Route enhancer 

Import route enhancer by adding following lines at the bottom of your site config.yaml:

imports:
  - { resource: "EXT:t3api/Configuration/Routing/config.yaml" }
Copied!

If you do not want to use import you can also manually add new route enhancer of type T3apiResourceEnhancer directly in your site configuration.

routeEnhancers:
  T3api:
    type: T3apiResourceEnhancer
Copied!

Default base path to api requests is: _api. To change it, it is needed to extend route enhancer configuration by basePath property, as in example below:

routeEnhancers:
  T3api:
    type: T3apiResourceEnhancer
    basePath: 'my_custom_api_basepath'
Copied!

Creating API resource 

Next step is to make an API resource from our entity. To map Extbase model to API resource it is just needed to add @SourceBroker\T3api\Annotation\ApiResource annotation to our model class and define at least one operation (endpoint):

use SourceBroker\T3api\Annotation\ApiResource;

/**
 * @ApiResource(
 *     collectionOperations={
 *          "get"={
 *              "path"="/items",
 *          },
 *     },
 *     itemOperations={
 *          "get"={
 *              "path"="/items/{id}",
 *          }
 *     },
 * )
 */
class Item extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
}
Copied!

After flushing caches the items are available under https://example.com/_api/items and single item under https://example.com/_api/items/1.

Backend module 

Backend module Web API shows the API of a site in Swagger UI - all resources and operations with their parameters, filters and response schemas, generated as OpenAPI specification from the configuration of the API resources. Select the site in the module header. The site needs the route enhancer, otherwise the module shows an error message.

Backend users need access to the module (admins have it by default).

The backend Content Security Policy of the module allows requests to the domains of all sites with the t3api route enhancer. Swagger UI does not use the online validator of swagger.io, so the URL of the specification is not sent outside of the TYPO3 instance.