Yancy::Controller::Yancy - A simple REST controller for Mojolicious
version 0.014
This module contains the routes that Yancy uses to work with the backend data. This API is used by the web application.
List the items in a collection. The collection name should be in the stash key collection. limit, offset, and order_by may be provided as query parameters.
collection
limit
offset
order_by
Add a new item to the collection. The new item should be in the request body as JSON. The collection name should be in the stash key collection.
Get a single item from a collection. The collection should be in the stash key collection, and the item's ID in the stash key id.
id
Update an item in a collection. The collection should be in the stash key collection, and the item's ID in the stash key id. The updated item should be in the request body as JSON.
Delete an item from a collection. The collection name should be in the stash key collection. The ID of the item should be in the stash key id.
To change how the API provides access to the data in your database, you can create a custom controller. To do so, you should extend this class and override the desired methods to provide the desired functionality.
package MyApp::Controller::CustomYancy; use Mojo::Base 'Yancy::Controller::Yancy'; sub list_items { my ( $c ) = @_; return unless $c->openapi->valid_input; my $items = $c->yancy->backend->list( $c->stash( 'collection' ) ); return $c->render( status => 200, openapi => $items, ); } package main; use Mojolicious::Lite; push @{ app->routes->namespaces }, 'MyApp::Controller'; plugin Yancy => { controller_class => 'CustomYancy', };
For an example, you could extend this class to add authorization based on your own requirements.
Yancy, Mojolicious::Controller
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2017 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.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.