APISchema - Schema for API
# bmi.def resource figure => { type => 'object', description => 'Figure, which includes weight and height', properties => { weight => { type => 'number', description => 'Weight(kg)', example => 50, }, height => { type => 'number', description => 'Height(m)', example => 1.6, }, }, required => ['weight', 'height'], }; resource bmi => { type => 'object', description => 'Body mass index', properties => { value => { type => 'number', description => 'bmi value', example => 19.5, }, }, required => ['value'], }; POST '/bmi/' => { title => 'BMI API', description => 'This API calculates your BMI.', destination => { controller => 'BMI', action => 'calculate', }, request => 'figure', response => 'bmi', }; # main.pl use APISchema::DSL; my $schema = APISchema::DSL::process { include 'bmi.def'; }; # Routing use APISchema::Generator::Router::Simple; my $router = do { my $generator = APISchema::Generator::Router::Simple->new; $generator->generate_router($schema); }; # Inject routes to an existing router object my $router = Router::Simple->new; $router->connect(...); my $generator = APISchema::Generator::Router::Simple->new; $generator->inject_routes($schema => $router); # Documentation use APISchema::Generator::Markdown; print do { my $generator = APISchema::Generator::Markdown->new; $generator->format_schema($schema); }; # Middleware (in app.psgi) enable "APISchema::ResponseValidator", schema => $schema; enable "APISchema::RequestValidator", schema => $schema;
APISchema is Schema for API
It provides DSL to describe API specification schema. It generates router, validator, document from API schema.
Copyright (C) hitode909 and tarao.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
hitode909 <hitode909@gmail.com>
tarao <tarao.gnn@gmail.com>
To install APISchema, copy and paste the appropriate command in to your terminal.
cpanm
cpanm APISchema
CPAN shell
perl -MCPAN -e shell install APISchema
For more information on module installation, please visit the detailed CPAN module installation guide.