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

NAME

Yancy::Help::Standalone - How to run Yancy without writing Perl code

VERSION

version 1.004

Getting Started

To run Yancy as a standalone application, you must create a yancy.conf configuration file that defines how to connect to your database and what the data inside looks like. See Yancy::Help::Config for details.

NOTE: Yancy does not have authentication or authorization built-in. If you want to control which users have access to data, you should use a plugin like Yancy::Plugin::Auth::Basic or an HTTP proxy with these features.

Once the application is started, you can navigate to http://127.0.0.1:3000/yancy to see the Yancy administration app. Navigate to http://127.0.0.1:3000/ to see the getting started page.

Rendering Content

In the standalone app, all paths besides the /yancy application are treated as paths to templates. If a specific template path is not found, Yancy will search for an index template in the same directory. If that template is not found, an error is returned.

The templates are found in the templates directory. You can change the root directory that contains the templates directory by setting the MOJO_HOME environment variable.

Template names must end with .format.ep where format is the content type (html is the default). You can render plain text (txt), JSON (json), XML (xml), and others.

Database content can be read by using the database helpers that Yancy provides.

  • yancy->list( $collection ) - Get a list of items

  • yancy->get( $collection, $id ) - Get a single item

  • yancy->set( $collection, $id, $data ) - Update an item

  • yancy->delete( $collection, $id ) - Delete an item

  • yancy->create( $collection, $data ) - Create an item

Some example template code:

    %# Get a list of people
    % my @people = app->yancy->list( 'people' );

    %# Show a list of people names 
    <ul>
        % for my $person ( @people ) {
            <li><%= $person->{name} %></li>
        % }
    </ul>

    %# Get a single person with ID 1
    % my $person = app->yancy->get( 'people', 1 );

    %# Write the person's name to the page
    <p>Hi, my name is <%= $person->{name} %>.</p>

More information about Mojolicious helpers is available at Mojolicious::Guides::Rendering.

Plugins

In standalone mode, you can configure plugins in the Yancy configuration file. Plugins can be standard Mojolicious::Plugins (with a name starting with Mojolicious::Plugin, or they can be specifically for Yancy (by extending Mojolicious::Plugin and having a name starting with Yancy::Plugin).

Plugins are configured as an array of arrays under the `plugins` key. Each inner array should have the plugin's name and any arguments the plugin requires, like so:

    {
        plugins => [
            [ 'PodRenderer' ],
            [ CGI => [ "/cgi-bin/script" => "/path/to/cgi/script.pl" ] ],
        ],
    }

SEE ALSO

Yancy

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Doug Bell.

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