Yancy::Controller::Yancy::API - (DEPRECATED) An OpenAPI REST controller for the Yancy editor
version 1.088
DEPRECATED: This module has been merged into the Yancy::Controller::Yancy class and the editor now uses that class by default.
This module contains the routes that Yancy uses to work with the backend data. This API is used by the Yancy editor.
List the items in a schema. The schema name should be in the stash key schema.
schema
Each returned item will be filtered by filters conforming with "yancy.filter.add" in Mojolicious::Plugin::Yancy that are passed in the array-ref in stash key filters_out.
filters_out
$limit, $offset, and $order_by may be provided as query parameters.
$limit
$offset
$order_by
Get a single item from a schema. The schema should be in the stash key schema.
The item's ID field-name is in the stash key id_field. The ID itself is extracted from the OpenAPI input, under a parameter of that name.
id_field
The return value is filtered like each result is in "list".
Create or update an item in a schema. The schema should be in the stash key schema.
The item to be updated is determined as with "get", if any. The new item is extracted from the OpenAPI input, under parameter name newItem, and must be a hash/JSON "object". It will be filtered by filters conforming with "yancy.filter.add" in Mojolicious::Plugin::Yancy that are passed in the array-ref in stash key filters, after the schema and property filters have been applied.
newItem
filters
Delete an item from a schema. The schema name should be in the stash key schema.
The item to be deleted is determined as with "get".
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 Yancy::Controller::Yancy and override the desired methods to provide the desired functionality.
package MyApp::Controller::CustomYancyAPI; use Mojo::Base 'Yancy::Controller::Yancy'; sub list { my ( $c ) = @_; return unless $c->openapi->valid_input; my $items = $c->yancy->backend->list( $c->stash( 'schema' ) ); return $c->render( status => 200, openapi => $items, ); } package main; use Mojolicious::Lite; push @{ app->routes->namespaces }, 'MyApp::Controller'; plugin Yancy => { editor => { default_controller => 'CustomYancyAPI', }, };
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) 2021 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.