The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WebAPI::DBIC::WebApp

VERSION

version 0.004002

SYNOPSIS

This minimal example creates routes for all data sources in the schema:

    $app = WebAPI::DBIC::WebApp->new({
        routes => [ map( $schema->source($_), $schema->sources) ]
    })->to_psgi_app;

is the same as:

    $app = WebAPI::DBIC::WebApp->new({
        routes => [
            { set => $schema->source('Artist') },
            { set => $schema->source('CD') },
            { set => $schema->source('Genre') },
            { set => $schema->source('Track') },
            ...
        ]
    })->to_psgi_app;

which is the same as:

    $app = WebAPI::DBIC::WebApp->new({
        routes => [
            ... # as above
        ],
        route_maker => WebAPI::DBIC::RouteMaker->new(
            resource_class_for_item        => 'WebAPI::DBIC::Resource::GenericItem',
            resource_class_for_item_invoke => 'WebAPI::DBIC::Resource::GenericItemInvoke',
            resource_class_for_set         => 'WebAPI::DBIC::Resource::GenericSet',
            resource_class_for_set_invoke  => 'WebAPI::DBIC::Resource::GenericSetInvoke',
            resource_default_args          => { },
            type_namer => WebAPI::DBIC::TypeNamer->new( # EXPERIMENTAL
                type_name_inflect => 'singular',    # XXX will change to plural soon
                type_name_style   => 'under_score', # or 'camelCase' etc
            ),
        ),
    })->to_psgi_app;

The elements in routes are passed to the specified route_maker. The elements can include any mix of result source objects, as in the example above, resultset objects, and WebAPI::DBIC::Route objects.

WebAPI::DBIC::WebApp uses the WebAPI::DBIC::RouteMaker object to convert and expands the given routes into a corresponding set of WebAPI::DBIC::Routes. For example, if we gloss over some details along the way, a routes specification like this:

    routes => [
        $schema->source('CD'),
    ]

is a short-hand way of writing this:

    routes => [
        { set => $schema->source('CD'), path => undef, ... }
    ]

is a short-hand way of writing this:

    routes => [
        $route_maker->make_routes_for( { set => $schema->source('CD'), ... } )
    ]

which is a short-hand way of writing this:

    $cd_resultset = $schema->source('CD')->resultset;
    $cd_path = $type_namer->type_name_for_resultset($cd_resultset);
    routes => [
        $route_maker->make_routes_for_resultset($cd_path, $cd_resultset, ...)
    ]

which is a short-hand way of writing this:

    $cd_resultset = $schema->source('CD')->resultset;
    $cd_path = $type_namer->type_name_for_resultset($cd_resultset);
    routes => [
        $route_maker->make_routes_for_set($cd_path, $cd_resultset),  # /cd
        $route_maker->make_routes_for_item($cd_path, $cd_resultset), # /cd/:id
    ]

which is a short-hand way of writing something much longer with explict calls to create the fully specified WebAPI::DBIC::Route objects.

The default URL path prefix is determined by the type_namer from the resultset source name using the type_name_inflect and type_name_style settings. For example, a result source name of ClassicAlbum would have a URL path prefix of /classic_albums by default, i.e. plural, and lowercased with underscores between words.

NAME

WebAPI::DBIC::WebApp - Build a Plack app using WebAPI::DBIC

AUTHOR

Tim Bunce <Tim.Bunce@pobox.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Tim Bunce.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.