',
isa => 'Str',
required => 1,
);
has json => (
is => 'ro',
isa => JSON::MaybeXS::JSON(),
default => sub { JSON::MaybeXS->new->allow_nonref->utf8->canonical },
);
sitory;
$ponapi_parameters->{version} = $self->version;
$ponapi_parameters->{json} = $self->json;
local $@;
my @ret;
eval {
@ret = $action_class->new($ponapi_para
=> [
{ ... }, ...
],
);
=head1 DESCRIPTION
Data Access Object for the JSON API. This sits in between a server
and a L<repository|"PONAPI::Repository">.
All public DAO met
age PONAPI::CLI::RunQuery;
use strict;
use warnings;
use JSON::MaybeXS;
use HTTP::Tiny;
sub run {
my ( $port, $query_string, $only_json ) = @_;
my $url = $query_string || random_url( $port
= HTTP::Tiny->new->get( $url, {
headers => {
'Accept' => 'application/vnd.api+json',
},
});
die "Failed to connect to a local server (try 'ponapi demo -s' to start
one)\n"
unless $res and ref($res) eq 'HASH' and $res->{status} < 500;
unless ( $only_json ) {
print "\nGET $url\n\n";
print $res->{protocol} . " " . $res->{status} . " " .
ons for PONAPI::Server
package PONAPI::Exception;
use Moose;
use Moose::Util qw/find_meta/;
use JSON::MaybeXS;
sub throw {
my $class_or_obj = shift;
die ( blessed $class_or_obj ? $class_or_obj
is => 'ro',
isa => 'Bool',
);
has json_api_version => (
is => 'ro',
isa => 'Str',
default => sub { '1.0' },
writer => '_set_json_api_version'
);
# Picked from Throwabl
has occured, please check server logs";
}
return $status, [], +{
jsonapi => { version => $self->json_api_version },
errors => [ { detail => $detail, status => $status } ],
->file('server.yml')->slurp );
}
sub read_config {
my $self = shift;
$self->_set_server_json_api_version;
$self->_set_server_sorting;
$self->_set_server_send_header;
$self->_set
f->_set_server_respond_to_updates_status;
$self->{'ponapi.mediatype'} = 'application/vnd.api+json';
return %{$self};
}
sub _set_server_respond_to_updates_status {
my $self = shift;
gured";
}
sub _set_server_json_api_version {
my $self = shift;
my $spec_version = $self->config->{server}{spec_version}
// die "[PONAPI Server] server JSON API version configuration
# ABSTRACT: PONAPI - Perl implementation of {JSON:API} (http://jsonapi.org/) v1.0
package PONAPI::Server;
use strict;
use warnings;
our $VERSION = '0.003003';
use Plack::Request;
use Plack::Respons
e;
use HTTP::Headers::ActionPack;
use Module::Runtime ();
use JSON::MaybeXS;
use URI::Escape qw( uri_unescape );
use PONAPI::Server::ConfigReader;
use PONAPI::Names qw( check_name );
use parent 'Pla
_TYPE => +{ __error__ => +[ 415, "{JSON:API} No {json:api} Media-Type (Content-Type / Accept)" ] },
ERR_MISSING_CONTENT_TYPE => +{ __error__ => +[ 415, "{JSON:API} Missing Content-Type header" ]
# ABSTRACT: DAO request class
package PONAPI::DAO::Request;
use Moose;
use JSON::MaybeXS;
use PONAPI::Document;
has repository => (
is => 'ro',
does => 'PONAPI::Repository',
r
> sub { 1 },
writer => '_set_is_valid',
);
has json => (
is => 'ro',
isa => JSON::MaybeXS::JSON(),
default => sub { JSON::MaybeXS->new->allow_nonref->utf8->canonical },
);
SCRIPTION
This module implements the L<member name restrictions|http://jsonapi.org/format/#document-member-names>
from the {json:api} specification; it can be used by repositories
to implement strict
and negative values: "no", 0 & "false"
server:
spec_version: "1.0" # {json:api} version
sort_allowed: "false" # server-side sorting support
send_version
map(qq< INSERT INTO articles (title, body, created, updated, status) VALUES $_>,
q<("JSON API paints my bikeshed!", "The shortest article. Ever.",
"2015-05-22 14:56:29", "20
ttp://jsonapi.org/format/#crud-updating-relationship-responses-204
# Basically, we return a 204, UNLESS it's an ->update() call, in which
# case it has to return a 404:
# http://jsonapi.or
in "/" => grep defined, '', @{$self}{qw/type id rel_type/} );
return $link . " => " . $self->json->encode( $self->data );
}
no PONAPI::Constants;
no Moose::Role; 1;
__END__
=pod
=encoding UTF
ce: "
. $self->type
. " => "
. $self->json->encode( $self->data )
);
$doc->set_status(201) unless $doc->has_status;
er" ],
[ "p|port=i", "Specify a port for the server (default=5000)" ],
[ "j|json", "JSON-only output" ],
);
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
$sel
opt->{q};
}
$self->{only_json} = !!( $opt->{json} || $opt->{j} );
$self->usage_error("JSON-only works just in Query mode")
if $self->{only_json} and !exists $opt->{q};
}
sub exe
CLI::RunQuery;
PONAPI::CLI::RunQuery::run( $self->{port}, $self->{query_string}, $self->{only_json} );
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
PONAPI::CLI::Command::demo - ponapi demo
ON
version 0.003003
=head1 DESCRIPTION
The origin of the name PONAPI (pronounced: Po-Na-Pi) is JSONAPI.
We jokingly decided to replace the JavaScript reference (JS) with a Perl one (P).
This docum
y PSGI-compatible utility
to run the application:
plackup -p 5000 myapp.psgi
Any L<{json:api}|http://jsonapi.org/> compliant client can then access your application:
$ perl -MPONAPI::Client
ion/vnd.api+json" 'http://0:5000/people/88
That'll give you the default options, with the default repository; for a real
world scenario, you'll have to get your hands dirty.
Because {json:api} exten