it as a micro-framework:
in app.psgi
use Plack::Request;
use Plack::ResponseHelper json => 'JSON',
text => 'Text';
my $app = sub {
my $env = shift
$form);
};
somewhere in your controllers
sub my_controller {
...
return json => {status => 'ok', data => [1, 2, 3]};
}
# or
sub dummy_controller {
return
s Plack's specifics.
Bundled with
L<Plack::ResponseHelper::Attachment>,
L<Plack::ResponseHelper::JSON>,
L<Plack::ResponseHelper::Redirect>,
L<Plack::ResponseHelper::Text>.
=head1 METHODS
=head2 use
d, col_int, col_text, col_real FROM datatable', [qw{id col_int col_text col_real}] );
$c->render( json => $res );
=cut
sub new {
my $class = shift;
my $self = {};
$self = {@_};
die("Undefined
package WWW::Foursquare::Response;
use strict;
use warnings;
use JSON;
our %ERROR_TYPE = (
invalid_auth => 'OAuth token was not provided or was invalid',
param_error => 'A re
elf, $class;
return $self;
}
sub process {
my ($self, $res) = @_;
my $data = decode_json($res->content());
my $code = $res->code();
# response is OK
return $data->{response}
ad1 SYNOPSIS
package Point;
use Moose;
use MooseX::Storage;
with Storage('format' => 'JSON', 'io' => 'File');
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => '
ad1 SYNOPSIS
package Point;
use Moose;
use MooseX::Storage;
with Storage('format' => 'JSON', 'io' => 'File');
has 'x' => (is => 'rw', isa => 'Int');
has 'y' => (is => 'rw', isa => '
=>'HashRef',
builder=>'_build_normalized');
sub _build_normalized {
return +{
JSON => 'application/json',
JS => 'application/javascript',
PERL => 'application/perl',
HTML => 'tex
sub start : POST Chained('/') CaptureArg(0) { ... }
sub is_json : Chained('start') Consumes('application/json') { ... }
sub is_urlencoded : Chained('start') Consumes('applicat
form-data') { ... }
## Alternatively, for common types...
sub is_json : Chained('start') Consume(JSON) { ... }
sub is_urlencoded : Chained('start') Consumes(UrlEncoded) { ...
tempt to encode C<application/json> since the two most commonly used
approaches (L<Catalyst::View::JSON> and L<Catalyst::Action::REST>) have already configured
their JSON encoders to produce properly
nses. If you are rolling your
own JSON encoding, you may need to set the encoder to do the right thing (or override
the global regular expression to include the JSON media type).
=head2 Encoding wit
on class, which we don't have an instance of, ewwwww
# Also, naughty modules like Catalyst::View::JSON try to write to _everything_,
# so spit a warning, ignore that (and try to do the right thing any
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('Runtime');
my $result = $client->public_timeline;
say "request e
package Mojolicious::Plugin::QooxdooJsonrpc;
use Mojo::Base 'Mojolicious::Plugin';
use File::Spec::Functions qw(splitdir updir catdir file_name_is_absolute);
use Cwd qw(abs_path);
our $VERSION = '0.
available and compiles at startup time and not
# only on demand.
use MojoX::Dispatcher::Qooxdoo::Jsonrpc;
sub register {
my ($self, $app, $conf) = @_;
# Config
$conf ||= {};
my $roo
$conf->{services};
my $path = $conf->{path} || 'jsonrpc';
my $r = $app->routes;
$r->route($root.$path)->to(
controller => 'Jsonrpc',
action => 'dispatch',
na
er::MultiPart'
);
my $json_parser = HTTP::Entity::Parser->new();
$json_parser->register(
'application/x-www-form-urlencoded',
'HTTP::Entity::Parser::UrlEncoded'
);
$json_parser->register(
t'
);
$json_parser->register(
'application/json',
'HTTP::Entity::Parser::JSON'
);
my $json_only_parser = HTTP::Entity::Parser->new();
$json_only_parser->register(
'application/json',
'HTTP::Entity::Parser::JSON'
);
sub _build_request_body_parser {
my $self = shift;
if ( $self->env->{'kossy.request.parse_json_body'} ) {
return $json_parser;
}
$default_parse
(
new => 1,
rw => [qw/req res stash args tx debug json_serializer/]
);
use Kossy::Exception;
our $VERSION = '0.63';
# for IE7 JSON venularity.
# see http://www.atmarkit.co.jp/fcoding/articl
es/webapp/05/webapp05a.html
# Copy from Amon2::Plugin::Web::JSON => Fixed to escape only string parts
my %_ESCAPE = (
'+' => '\\u002b', # do not eval as UTF-7
'<' => '\\u003c', # do not eval a
my $body = shift;
$body =~ s!([+<>])!$_ESCAPE{$1}!g;
return qq("$body");
}
sub escape_json {
my $self = shift;
my $body = shift;
# escape only string parts
$body =~ s/"((?:
server: irc.perl.org
nick: hlagherf32fr
The configuration file is in L<YAML|YAML> or L<JSON|JSON> format. It consists
of a hash containing C<global_plugins>, C<local_plugins>, C<networks>, C<
s;
use MooseX::Types -declare => [ qw(UriPath Boolean HTTPMethod JSONBoolean) ];
use MooseX::Types::Moose qw(Str Int Defined);
use JSON;
subtype UriPath,
as Str,
where { $_ =~ m!^/! },
me
as Int,
where { $_ eq 1 || $_ eq 0 };
subtype JSONBoolean,
as Defined,
where { JSON::is_bool($_) };
coerce Boolean,
from JSONBoolean,
via { return int($_) ? 1 : 0 },
fro
ilename => 'logfile'
)
);
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable( 'LogDispatch', logger => $log );
=head1 AUTHOR
franck cuny <franck@lumb
package Net::DiffBot;
use 5.006;
use strict;
use warnings;
use LWP::UserAgent;
use JSON::XS;
use URI::Escape qw(uri_escape);
use HTTP::Request;
my $endpoint_url = 'http://www.diffbot.com/api/article
my $data;
eval {
$data = decode_json($response->content);
};
if ($@) {
warn "ERROR decoding JSON response";
return undef;
}
my $data;
eval {
$data = decode_json($response->content);
};
if ($@) {
warn "ERROR decoding JSON response";
return undef;
}
=> 'text/plain'], 'ok');
}
};
my $client = Net::HTTP::Spore->new_from_spec('spec.json');
$client->enable('Mock', tests => $mock_server);
my $res = $client->my_rest_method();
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable( 'Redirection', max_redirect => 2 );
# or
$client->enable( 'Redir
ss::Accessor::Lite (
new => 1,
rw => [qw/req res stash args tx debug/]
);
use JSON qw//;
my $_JSON = JSON->new()->ascii(1);
my %_ESCAPE = (
'+' => '\\u002b', # do not eval as UTF-7
'
body );
$self->res;
}
sub render_json {
my $self = shift;
my $obj = shift;
# defense from JSON hijacking
# Copy from Amon2::Plugin::Web::JSON
if ( !$self->req->header('X-Requ
elf->halt(403,"Your request is maybe JSON hijacking.\nIf you are not a attacker, please add 'X-Requested-With' header to each request.");
}
# for IE7 JSON venularity.
# see http://www.atm
ase JSON)
# pack the class into a JSON string
$p->freeze({ format => 'JSON' }); # { "__CLASS__" : "Point", "x" : 10, "y" : 10 }
# pack the class into a JSON string using parameterized JSONpm r
> [ JSONpm => { json_opts => { pretty => 1 } } ] });
# unpack the JSON string into a class
my $p2 = Point->thaw(
'{ "__CLASS__" : "Point", "x" : 10, "y" : 10 }',
{ format => 'JSON' }
ally use them (see the
SYNOPSIS for more info)
=head1 SUPPORTED FORMATS
=over 4
=item I<JSON>
=item I<JSONpm>
=item I<YAML>
=item I<Storable>
=back
=head1 SUPPORTED I/O
=over 4
=item I<File>