Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xperseguers/t3ext-routing

TYPO3 Extension routing
https://github.com/xperseguers/t3ext-routing

Last synced: 1 day ago
JSON representation

TYPO3 Extension routing

Awesome Lists containing this project

README

        

# Request Routing Service

Service to route HTTP/REST requests to your own controller/actions.

**Good to know:** The routing is inspired by the way Flow's router works
([read more](https://flowframework.readthedocs.io/en/6.3/TheDefinitiveGuide/PartIII/Routing.html)).

## What does it do?

This extension lets you route requests like:

```
http://localhost/routing/extension-key/my-demo/1234
http://localhost/routing/extension-key/my-demo/1234.json
http://localhost/routing/extension-key/my-demo/99
```

to any controller/action based on a YAML-based routing configuration. In this example, where `1234` and `99` will be
mapped to some method argument (and converted to domain object if needed) and `json` will set the response format to
`json`.

## Sample Routing

The routing is stored as `Configuration/Routes.yaml` (or `Configuration/Routes.yml`) and looks like that

```
-
name: 'Demo action with a parameter in a given format (JSON, ...)'
uriPattern: 'my-demo/{value}.{@format}'
defaults:
'@package': 'MyVendor.ExtensionKey'
'@plugin': 'API'
'@controller': 'Dummy'
'@action': 'demo'
-
name: 'Demo action with a parameter'
uriPattern: 'my-demo/{value}'
defaults:
'@package': 'MyVendor.ExtensionKey'
'@plugin': 'API'
'@controller': 'Dummy'
'@action': 'demo'
```

The name of the route is sent as additional header in the response:

![Additional HTTP header "X-Causal-Routing-Route"][http-header]

[http-header]: https://raw.githubusercontent.com/xperseguers/t3ext-routing/master/Documentation/Images/headers.png "Additional HTTP header 'X-Causal-Routing-Route'"

## Installation

1. Install extension with packagist:

```
composer req causal/routing
```

2. Go to Extension Manager and activate extension `routing`

3. Add a rewrite rule to your `.htaccess`:

```
RewriteRule ^routing/(.*)$ /index.php?eID=routing&route=$1 [QSA,L]
```

or, if you are using Nginx:

```
rewrite ^/routing/(.*)$ /index.php?eID=routing&route=$1 last;
```

This will have the effect of using this extension for handling requests starting with `routing/`.

**Tip:** If you need to support localization (`&L=`), then you should change the suggesting routing
above to include the root page uid of your website (`&id=`). This is needed because localization mode and
default language may differ in complex environments and thus cannot be inferred.

Read more in the [manual](https://docs.typo3.org/typo3cms/extensions/routing/).

## Compatibility with TYPO3 v8

Since [change 78002](https://docs.typo3.org/typo3cms/extensions/core/8.7/Changelog/8.5/Breaking-78002-EnforceCHashArgumentForExtbaseActions.html),
you need to adapt your TypoScript so that `cHash` is not required:

```
plugin.tx_ {
features {
requireCHashArgumentForActionArguments = 0
}
}
```