The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

APISchema - Schema for API

SYNOPSIS

# 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
my $schema = APISchema::DSL::process {
include 'bmi.def';
};
# Routing
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
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;

DESCRIPTION

APISchema is Schema for API

It provides DSL to describe API specification schema. It generates router, validator, document from API schema.

LICENSE

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.

AUTHORS

hitode909 <hitode909@gmail.com>

tarao <tarao.gnn@gmail.com>