eq 'dev' ) ) {
say $_->error for $context->stash->{'slick.errors'}->@*;
$context->json(
[ map { $_->to_hash } $context->stash->{'slick.errors'}->@* ] );
}
# HEAD r
s a simple example app that takes advantage of 2 databases,
has a migration, and also serves some JSON.
use 5.036;
use Slick;
my $s = Slick->new;
# Both MySQL and Postgres are supp
_one('user', { id => $context->params('id') });
# Render the user hashref as JSON.
$context->json($user);
});
$s->post('/users' => sub {
my $app = shift;
my $
ef);
use Module::Runtime qw(require_module);
use URI::Query;
use URL::Encode;
use JSON::Tiny qw(encode_json decode_json);
use YAML::Tiny;
use Time::HiRes;
has id => (
is => 'ro',
isa
+{
'application/json' => sub { return decode_json(shift); },
'text/json' => sub { return decode_json(shift); },
'application/json; encoding=utf8' =>
pes->{ $self->request->content_type };
if ( $self->request->content_type =~ 'json' ) {
return decode_json( $self->request->content );
}
elsif ( $self->request->content_type =~ 'x-
tation;
use 5.036;
use Exporter qw(import);
use Carp qw(carp);
use JSON::Tiny qw(decode_json encode_json);
use Scalar::Util qw(blessed);
our @EXPORT_OK = qw(cacheable);
sub cacheable
he_obj->get( $context->request->uri ) ) {
my $response =
decode_json( $cache_obj->get( $context->request->uri ) );
$context->from_psgi($response);
ode_json $context->to_psgi;
if ( blessed( $cache_obj->{_executor} ) =~ /Memcached/x ) {
$cache_obj->set(
$context->request->uri => $json =>
my $slick = Slick->new;
$router->get('/bob' => sub { my ($app, $context) = @_; $context->json({hello => 'world'}); });
# You may also add events that will be dispatched between global an