1-01 00:00:00
say $date2; # 2013-12-31 15:00:00
=item L<Data::Recursive>'s C<clone>
=item L<JSON> serialization with convert_blessed
Serializes to C<epoch()>
=back
=head1 PACKAGES
C<Date>
# Load your specification
$self->plugin("OpenAPI" => {url => $app->home->rel_file("myapi.json")});
$self->hook(around_action => sub {
my ($next, $c, $action, $last) = @_;
#
ecification>
and generates routes and input/output rules from it. See L<JSON::Validator> for
L<supported schema file formats|JSON::Validator/Supported schema formats>.
{
"openapi": "3.0.2",
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
"description": "Pet response",
"content": {
"application/json": {
"schema": {
"type": "object",
"prop
:Parameters;
use Mojo::Base 'Mojolicious::Plugin';
use JSON::Validator::Util qw(is_bool schema_type);
use Mojo::JSON qw(encode_json decode_json);
sub register {
my ($self, $app, $config) = @_;
o::Asset');
$c->res->headers->content_type('application/json;charset=UTF-8')
unless $c->res->headers->content_type;
return encode_json($_[0]);
}
sub _helper_build_schema_request {
my $c =
the already parsed json() or fallback to manually decoding the request
# since it will make the eval {} fail on invalid json.
$res->{value} //= $c->req->json // decode_json $c->req->body;
e::API::Ye;
use strict;
use warnings;
our $VERSION = '1.0.2';
use HTTP::Tiny;
use JSON qw/decode_json/;
use Util::H2O::More qw/baptise d2o/;
use constant {
BASEURL => "https://api.k
sub get {
my $self = shift;
my $resp = d2o $self->ua->get(BASEURL);
return d2o decode_json $resp->content;
}
sub quote {
my $self = shift;
return $self->get->quote;
}
1;
__END__
jolicious::Plugin::OpenAPI::SpecRenderer;
use Mojo::Base 'Mojolicious::Plugin';
use JSON::Validator;
use Mojo::JSON;
use Scalar::Util qw(blessed);
use constant DEBUG => $ENV{MOJO_OPENAPI_DEBUG} |
fication} // 1) {
my $spec_route = $openapi->route->get(
'/',
[format => [qw(html json)]],
{format => undef},
sub { shift->openapi->render_spec(@_) }
);
my $name =
>render(json => {errors => [{message => 'No spec defined.'}]}, status => 404)
unless my $schema = $validator->get([paths => $path, $method ? ($method) : ()]);
return $c->render(
json => {
message => "Some error!", path => "/Whatever"}];
return [{message => "Some error!"}];
return [JSON::Validator::Error->new];
=back
On success, the following headers will be set, unless already se
startup {
my $app = shift;
$app->plugin(OpenAPI => {
url => "data:///security.json",
security => {
dummy => sub {
my ($c, $definition, $scopes, $cb) = @_;
is that this API call in the past has returned
# a JSON hash rather than an array in some cases; in other cases
# it has returned an empty JSON array
if (my $ref = $resp->shift) {
return spr
str eq "JSON") {
require JSON;
my $j = JSON->new->allow_nonref;
$h->{_en} = sub { $j->utf8->encode ($_[0]) };
$h->{_de} = sub { $j->decode ($_[0]) };
}
elsif ($str eq "JSON::Maybe
require JSON::MaybeXS;
my $j = JSON::MaybeXS->new->allow_nonref;
$h->{_en} = sub { $j->utf8->encode ($_[0]) };
$h->{_de} = sub { $j->decode ($_[0]) };
}
elsif ($str eq "JSON::SIMD")
require JSON::SIMD;
my $j = JSON::SIMD->new->allow_nonref;
$h->{_en} = sub { $j->utf8->encode ($_[0]) };
$h->{_de} = sub { $j->decode ($_[0]) };
}
elsif ($str eq "JSON::Syck") {
package Mojolicious::Plugin::OpenAPI;
use Mojo::Base 'Mojolicious::Plugin';
use JSON::Validator;
use Mojo::JSON;
use Mojo::Util;
use Mojolicious::Plugin::OpenAPI::Parameters;
use constant DEBUG => $
ute => sub {undef};
has validator => sub { JSON::Validator::Schema->new; };
sub register {
my ($self, $app, $config) = @_;
$self->validator(JSON::Validator->new->schema($config->{url} || $co
c = shift;
my $path = shift // 'for_current';
my $self = _self($c);
# Get spec by valid JSON pointer
return $self->validator->get($path) if ref $path or $path =~ m!^/! or !length $path;
<Data::Recursive>'s C<clone>
=item serializing/deserializing via Storable
=item serializing via JSON::XS with C<convert_blessed> flag enabled
=back
=head1 REGISTERING SCHEMAS
=head2 PURE PERL I
pecification>
and generate routes and input/output rules from it. See L<JSON::Validator> for
L<supported schema file formats|JSON::Validator/Supported schema formats>.
{
"swagger": "2.0",
"
from the keys
under C</pets>.
The different parts of the specification can also be retrieved as JSON using
the "OPTIONS" HTTP method. Example:
OPTIONS /api/pets
OPTIONS /api/pets?method=get
No
h
The C<basePath> will also be used to add a route that renders back the
specification either as JSON or HTML. Examples:
=over 2
=item * http://example.com/api.html
Retrieve the expanded version o
use v5.10;
use strict;
use warnings;
our $VERSION = '0.9.10';
use HTTP::Tiny;
use JSON qw/decode_json/;
use Util::H2O::More qw/baptise ddd HTTPTiny2h2o h2o/;
use constant {
BASEURL
odule is the first one written using L<Util::H2O::More>'s C<HTTPTiny2h2o>
method that looks for C<JSON> in the C<content> key returned via L<HTTP::Tiny>'s
response C<HASH>.
=head1 METHODS
=over 4
=
lic::APIs;
use strict;
use warnings;
our $VERSION = '0.9.10';
use HTTP::Tiny;
use JSON qw/decode_json/;
use Util::H2O::More qw/baptise d2o HTTPTiny2h2o/;
use constant {
BASEURL => "
odule is the first one written using L<Util::H2O::More>'s C<HTTPTiny2h2o>
method that looks for C<JSON> in the C<content> key returned via L<HTTP::Tiny>'s
response C<HASH>.
=head1 METHODS
=over 4
=
100 IP Geolocation API
92 99 French Address API
94 95 Carbon Intensity API
90 95 JSONPlaceholder
88 95 Stadt Land Fluss
80 95 Dungeons and Dragons
77 95 Digimon API
PI::Stonks;
use strict;
use warnings;
our $VERSION = '1.0.2';
use HTTP::Tiny;
use JSON qw/decode_json/;
use Util::H2O::More qw/baptise d2o/;
use constant {
BASEURL => "https://trade
my $self = shift;
my $resp = d2o $self->ua->get(BASEURL);
return d2o -autoundef, decode_json $resp->content;
}
sub stonks {
my $self = shift;
return $self->get;
}
1;
__END__
=hea
eters are accepted.
=item C<stonks>
Object method that returns an ARRAY reference (based on the JSON returned
by this service), that's been give the additional ARRAY vmethods via
L<Util::H2O::More>
kage WebService::Slack::WebApi::Client;
use strict;
use warnings;
use utf8;
use HTTP::AnyUA;
use JSON;
use WebService::Slack::WebApi::Exception;
use Class::Accessor::Lite::Lazy (
new => 1,
$path,
[
%{ $params },
],
\%options,
);
return decode_json $response->{content} if $response->{success};
WebService::Slack::WebApi::Exception::FailureR
response => $response,
);
}
sub request_json {
my ($self, $path, $params) = @_;
my %headers = ( 'Content-Type' => 'application/json' );
if( $self->token && $params->{'http_auth'
dicts") %path340;
path341 = ( "/social/dev/dicts_json") %path341;
path342 = ( "/social/dev/dicts_json_br") %path342;
path343 = ( "/social/dev/dicts_json_gz") %path343;
path344 = ( "/social/dev/git_inf
8) %path549;
path550 = ( "/social/dev/dicts" any "json" ( ( "/" (any - ("/"))+ )* ) >cs159 %c_159) %path550;
path551 = ( "/social/dev/dicts" any "json" any "br" ( ( "/" (any - ("/"))+ )* ) >cs160 %c_1
60) %path551;
path552 = ( "/social/dev/dicts" any "json" any "gz" ( ( "/" (any - ("/"))+ )* ) >cs161 %c_161) %path552;
path553 = ( "/social/dev/git_info" ( ( "/" (any - ("/"))+ )* ) >cs162 %c_162) %pa
::ChuckNorris;
use v5.10;
use strict;
our $VERSION = '1.0.1';
use HTTP::Tiny;
use JSON qw/decode_json/;
use Util::H2O::More qw/baptise d2o h2o/;
use constant {
BASEURL => "https://a
%s/%s", BASEURL, "categories";
my $resp = h2o $self->ua->get($URL);
my $ret = d2o decode_json $resp->content;
return scalar $ret;
}
sub random {
my $self = shift;
my $args = d2
l response (status: %d)\n", $resp->status ) if ( $resp->status != 200 );
my $ret = d2o decode_json $resp->content;
return $ret->value;
}
sub search {
my $self = shift;
my $args = h2
v/dicts/...
/social/dev/dicts.json/...
/social/dev/dicts_json
/social/dev/dicts.json.br/...
/social/dev/dicts_json_br
/social/dev/dicts.json.gz/...
/social/dev/dicts_json_gz
/social/dev/git_info
/soci