NAME

App::Manoc::Controller::APIv1 - Base class for API controllers

VERSION

version 2.99.2

SYNOPSIS

package App::Manoc::APIv1::FooApi;

BEGIN { extends 'App::Manoc::Controller::APIv1' }

sub foo_base : Chained('deserialize') PathPart('foo') CaptureArgs(0) {
  my ( $self, $c ) = @_;
  $c->stash( resultset => $c->model('ManocDB::Foo') );
}

sub foo_post : Chained('foo_base') PathPart('') POST {
  my ( $self, $c ) = @_;

  $c->stash(
      api_validate => {
          type  => 'hash',
          items => {
              foo_name => {
                  type     => 'scalar',
                  required => 1,
              },
              bar_list => {
                  type     => 'array',
                  required => 1,
              },
          },
      }
  );

DESCRIPTION

This class should be used for implementing API controllers which manage entry point in api/v1. It disables CRSF and requires HTTP authentication.

Data can be validated using App::Manoc::Utils::Validate via validate method.

Responses are generated using api_response_data stash element.

Error messages are be stored in api_message or api_field_errors.

ACTIONS

base

Path api/v1. Require HTTP Authentication

METHODS

begin

Set is_api in stash

deserialize

Chained to base, stores request body data in api_request_data in stash.

end

Genereates http status code preparare data (API results or validation errors) for JSON serializer.

validate

Read data from api_request_data stash value and validates with App::Manoc::Utils::Validate using rules in api_validate stash value.

AUTHORS

  • Gabriele Mambrini <gmambro@cpan.org>

  • Enrico Liguori

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Gabriele Mambrini.

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