No description or website provided.
Perl
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/Amon2/Web
t
xt
.gitignore
.shipit
.travis.yml
Build.PL
Changes
MANIFEST
MANIFEST.SKIP
README.pod

README.pod

NAME

Amon2::Web::JSONAPI::DFV - API dispatcher DSL for Amon2

SYNOPSIS

    package MyApp::Web;

    use Amon2::Web::JSONAPI::DFV;

    get '/api/v1/foo' => +{
        optional => [qw/company fax country/],
        required => [qw/fullname phone email address/],
    } => sub {
        my ($c, $args, $valids) = @_;
        # $args is a captured arguments from Router::Simple.
        # $valids is a hashref, contains valid parameters.
        ...
        return +{
            foo => 'bar',
        };
    };

    package main;

    my $psgi_app = MyApp::Web->to_app();

DESCRIPTION

Amon2::Web::JSONAPI::DFV provides API dispatcher DSL for Amon2 using Data::FormValidator.

You can write a JSON API very easily with parameter validation.

FUNCTIONS

any($path:Str[, $profile:HashRef], $code:CodeRef)

Handles in $path with Data::FormValidator profile $profile, and run $code.

$path is passed to Router::Simple.

$profile is a Data::FormValidator's profile in HashRef. Please look Data::FormValidator's manual for more details.

$code gets three arguments. $c is a Amon2's context object. $valids is a valid parameters by Data::FormValidator. $args is a captured parameters by Router::Simple.

You can omit the $profile argument if the API doens't need to validate parameters.

Return Value: useless.

get($path:Str[, $profile:HashRef], $code:CodeRef)

Same as any, but invokes only in GET method.

When get Non-GET request, server returns 405 Method Not Allowed.

post($path:Str[, $profile:HashRef], $code:CodeRef)

Same as any, but invokes only in POST method.

When get Non-POST request, server returns 405 Method Not Allowed.

Making document from routes.

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>

SEE ALSO

Amon2, Data::FormValidator

LICENSE

Copyright (C) Tokuhiro Matsuno

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