zfcampus / zf-versioning

BSD 3-Clause "New" or "Revised" License
11 stars 7 forks source link

proposal for more flexibility in URL based versioning #8

Closed bvarent closed 9 years ago

bvarent commented 9 years ago

situation

As stated in the docs, and verifiable in the code:

If a particular route is a child route, the chain will happen at the top-most ancestor.

Also, the version segment is always _pre_pended to the route.

request

I would like to have an option to get the version segment appended instead of prepended. And to have it applicable to a child route. This way I could keep my route configuration nested. And I wouldn't have to specify an uri configuration key for each resource.

example case

Desired route: /module-name/api/v1/some-resource/1234

'zf-versioning' => array(
    'append_version_segment' => true,
    'allow_child_routes' => true,
    'uri' => array(
        'vendor.module/api',
    ),
),
'router'=> array('routes' => array(
    'vendor.module' => array(
        'type' => 'literal',
        'options' => array(
            'route' => '/module-name',
            'defaults' => array(
                'controller' => __NAMESPACE__ . '\Controller\Foo', // for a web UI
            )
        ),
        'child_routes' => array(
            'api' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/api'
                ),
                'child_routes' => array(
                    'delivery-method' => array(
                        'type' => 'Segment',
                        'options' => array(
                            'route' => '/some-resource[/:id]',
                            'defaults' => array(
                                'controller' => __NAMESPACE__ . '\Api\V1\SomeResourceController',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
)),

discussion

Do you think this is useful and makes sense? I would be happy to code it.

weierophinney commented 9 years ago

Honestly, URI-based versioning is an anti-pattern. The only reasons we support it out-of-the-box are:

Appending the version segment is terrible; the last item in the URI path should be the resource you are fetching, not metadata.

9 will let you do it, and I'll likely merge it as I like the idea of being able to refactor my routes to be nested children. But I would encourage you to re-consider your needs for having the version in the URI in the first place.