[Catalyst] Optional path prefix

Bill Moseley moseley at hank.org
Tue Oct 22 16:09:16 GMT 2013


On Mon, Oct 21, 2013 at 9:08 AM, John Napiorkowski <jjn1056 at yahoo.com>wrote:

> I'd probably myself want some plack middleware that would convert
>
> /api/v1/account/<id>/widget/<id>
>
>
> to
>
>
> /account/<id>/widget/<id>    with accept type application/mycompany.v1+js=
on
>

I guess that would separate that out of the app.

I'm currently using this approach in an app role:

    my @path_seg =3D split '/', $c->req->path, -1;
    my $base_uri =3D $c->req->base;

    return unless @path_seg && $path_seg[0] =3D~ /$path_prefix_version_rege=
x/;

    my $match =3D $1;

    die "path_prefix_version_regex ($path_prefix_version_regex) matched but
failed to capture any value"
        unless defined $match;

    $c->stash->{path_prefix_version} =3D $match;
    $base_uri->path( $base_uri->path . shift( @path_seg ) . '/' );

    # Force $req->path to reload _path next time $req->path is called.
    $c->req->_clear_path;




>
> But you could probably support changing the URL path pretty easily with
> either setting the controller namespace to have v1 in it, or adding a root
> tot he change that specifies the new extra path part.
>

But would that support it being an optional prefix?   Need both to work at
the same time.




> I understand the development word seems to prefer making version part of
> the path.  depending on your logic and the type of changes introduced it
> may or may not be easier to take one approach or the other.
>

It does seem like that.   Deciding to go with the flow vs. doing it the
"right" way is the decision to be made.   I like your suggestion to map it
to an Accept header -- best of both worlds.


-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131022/331d2=
462/attachment.htm


More information about the Catalyst mailing list