[Flow] Routes and optional arguments/parameters

Bastian Waidelich bastian at typo3.org
Mon Oct 14 15:08:39 CEST 2013


Søren Malling wrote:

Hi Søren,

> I'm writing my own API at the moment for a project and I'm in the part of
> configuring my routes [...]

> -
>    name : 'API'
>    uriPattern: 'api/{@action}(/{object})'
>    acceptedHttpMethods: ['POST', 'GET', 'PUT', 'DELETE']
>    appendExceedingArguments: TRUE
>    defaults:
>      '@package': 'Vender.Package'
>      '@controller': 'Rest'
>      '@format': 'json'
> -
>    name : 'API'
>    uriPattern: 'api'
>    acceptedHttpMethods: ['GET']
>    appendExceedingArguments: TRUE
>    defaults:
>      '@package': 'Vendor.Package'
>      '@controller': 'Rest'
>      '@format': 'json'
>      '@action': 'help'
>
> ----------------

> When I write the /api address i get the help function and the returned JSON
> but when i add the "@action" like this
>
> http://host.tld/api/team
>
> I get this error in return
>
> No controller could be resolved [...]

First a few hints:

* It helps if you give your routes unique names - The system log 
(Data/Logs/System_<Context>.log) will refer to them.
* The HTTP Request method filter is just called "httpMethods", not 
"acceptedHttpMethods" (see [1])
* Only use "appendExceedingArguments" and optional route parts if you 
really need them, they make debugging slightly harder

Now to your issue:

For optional route parts you'll have to define a default (see [2]).

HTH


[1] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/Routing.html#request-methods
[2] 
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/Routing.html#optional-route-parts

-- 
Bastian Waidelich
--
Core Developer Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list