Discussion:
[Catalyst] JSONP support Catalyst::Controller::DBIC::API
Rajesh Kumar Mallah
2017-03-09 02:15:17 UTC
Permalink
Hi ,

How to get JSON response body wrapped in a callback function
call (a.k.a JSONP) when using Catalyst::Controller::DBIC::API::REST

I use Catalyst::Controller::DBIC::API and 'end' function
in ControllerBase is like below:

sub end : Private {
my ( $self, $c ) = @_;

##
# code for manipulating stash here
##

$c->forward('serialize');
}

=============================================
In Catalyst/Controller/DBIC/API.pm

# from Catalyst::Action::Serialize
sub serialize : ActionClass('Serialize') { }

=============================================


My other JSON responses which are rendered via MyApp::View::JSON
can be modified as JSONP compatible as i have below in my App config

__PACKAGE__->config({
'View::JSON' => {
allow_callback => 1, # defaults to 0
},
});


===============================================


The problem is only with automatically generated rest endpoints
from Catalyst::Controller::DBIC::API.

Thanks in anticipation.


Regds
mallah.




















_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Rajesh Kumar Mallah
2017-03-09 10:05:34 UTC
Permalink
For the time being i have modified and solved my issue as below:

sub end : Private {
my ( $self, $c ) = @_;

##
# code for manipulating stash here
##

$c->forward('serialize');

my $cb = $c->request->params->{callback} ;

if ($cb) {
my $body = \$c->res->body;
$$body = "$cb ($$body);";
$c->res->body($$body);
}

}


regds
mallah.
Post by Rajesh Kumar Mallah
Hi ,
How to get JSON response body wrapped in a callback function
call (a.k.a JSONP) when using Catalyst::Controller::DBIC::API::REST
I use Catalyst::Controller::DBIC::API and 'end' function
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
}
=============================================
In Catalyst/Controller/DBIC/API.pm
# from Catalyst::Action::Serialize
sub serialize : ActionClass('Serialize') { }
=============================================
My other JSON responses which are rendered via MyApp::View::JSON
can be modified as JSONP compatible as i have below in my App config
__PACKAGE__->config({
'View::JSON' => {
allow_callback => 1, # defaults to 0
},
});
===============================================
The problem is only with automatically generated rest endpoints
from Catalyst::Controller::DBIC::API.
Thanks in anticipation.
Regds
mallah.
_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Hartmaier Alexander
2017-03-14 16:48:41 UTC
Permalink
Looks like a code injection attack vector to me...

Patch + Tests for DBIC::API welcome!
Post by Rajesh Kumar Mallah
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
my $cb = $c->request->params->{callback} ;
if ($cb) {
my $body = \$c->res->body;
$$body = "$cb ($$body);";
$c->res->body($$body);
}
}
regds
mallah.
Post by Rajesh Kumar Mallah
Hi ,
How to get JSON response body wrapped in a callback function
call (a.k.a JSONP) when using Catalyst::Controller::DBIC::API::REST
I use Catalyst::Controller::DBIC::API and 'end' function
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
}
=============================================
In Catalyst/Controller/DBIC/API.pm
# from Catalyst::Action::Serialize
sub serialize : ActionClass('Serialize') { }
=============================================
My other JSON responses which are rendered via MyApp::View::JSON
can be modified as JSONP compatible as i have below in my App config
__PACKAGE__->config({
'View::JSON' => {
allow_callback => 1, # defaults to 0
},
});
===============================================
The problem is only with automatically generated rest endpoints
from Catalyst::Controller::DBIC::API.
Thanks in anticipation.
Regds
mallah.
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Rajesh Kumar Mallah
2017-03-16 17:07:37 UTC
Permalink
Ok are you suggesting DBIC::API needs to be enhanced for
JSONP support ?


Regds
Mallah.
Post by Hartmaier Alexander
Looks like a code injection attack vector to me...
Patch + Tests for DBIC::API welcome!
Post by Rajesh Kumar Mallah
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
my $cb = $c->request->params->{callback} ;
if ($cb) {
my $body = \$c->res->body;
$$body = "$cb ($$body);";
$c->res->body($$body);
}
}
regds
mallah.
Post by Rajesh Kumar Mallah
Hi ,
How to get JSON response body wrapped in a callback function
call (a.k.a JSONP) when using Catalyst::Controller::DBIC::API::REST
I use Catalyst::Controller::DBIC::API and 'end' function
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
}
=============================================
In Catalyst/Controller/DBIC/API.pm
# from Catalyst::Action::Serialize
sub serialize : ActionClass('Serialize') { }
=============================================
My other JSON responses which are rendered via MyApp::View::JSON
can be modified as JSONP compatible as i have below in my App config
__PACKAGE__->config({
'View::JSON' => {
allow_callback => 1, # defaults to 0
},
});
===============================================
The problem is only with automatically generated rest endpoints
from Catalyst::Controller::DBIC::API.
Thanks in anticipation.
Regds
mallah.
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Hartmaier Alexander
2017-03-17 10:06:20 UTC
Permalink
If someone wants JSONP support, yes.

Best regards, Alex
Post by Rajesh Kumar Mallah
Ok are you suggesting DBIC::API needs to be enhanced for
JSONP support ?
Regds
Mallah.
Post by Hartmaier Alexander
Looks like a code injection attack vector to me...
Patch + Tests for DBIC::API welcome!
Post by Rajesh Kumar Mallah
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
my $cb = $c->request->params->{callback} ;
if ($cb) {
my $body = \$c->res->body;
$$body = "$cb ($$body);";
$c->res->body($$body);
}
}
regds
mallah.
Post by Rajesh Kumar Mallah
Hi ,
How to get JSON response body wrapped in a callback function
call (a.k.a JSONP) when using Catalyst::Controller::DBIC::API::REST
I use Catalyst::Controller::DBIC::API and 'end' function
sub end : Private {
##
# code for manipulating stash here
##
$c->forward('serialize');
}
=============================================
In Catalyst/Controller/DBIC/API.pm
# from Catalyst::Action::Serialize
sub serialize : ActionClass('Serialize') { }
=============================================
My other JSON responses which are rendered via MyApp::View::JSON
can be modified as JSONP compatible as i have below in my App config
__PACKAGE__->config({
'View::JSON' => {
allow_callback => 1, # defaults to 0
},
});
===============================================
The problem is only with automatically generated rest endpoints
from Catalyst::Controller::DBIC::API.
Thanks in anticipation.
Regds
mallah.
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Rajesh Kumar Mallah
2017-03-17 10:22:38 UTC
Permalink
Thanks for clarifying .
I shall try to see and explore.


regds
mallah.
Post by Hartmaier Alexander
If someone wants JSONP support, yes.
Best regards, Alex
Post by Rajesh Kumar Mallah
Ok are you suggesting DBIC::API needs to be enhanced for
JSONP support ?
Regds
Mallah.
_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Rajesh Kumar Mallah
2017-03-19 08:28:37 UTC
Permalink
Hi ,

We know that Catalyst::Controller::DBIC::API supports paging
via list_count , list_page and list_offset options and
its possible to fetch a page of a large result set.

However what it does not seems to support is to tell
the View(caller) of how many records in total exists , ie
the total_entries of the Data::Page object.

This compels us to make two queries one to get the total count
and another to get the paged result.

Does this feature really does not exists or am I missing something?

(The reason I love and thoroughly use Catalyst::Controller::DBIC::API is
that it allows me to be lazy :p )

regds
Rajesh Kumar Mallah.




_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Dimitar Petrov
2017-03-19 17:38:29 UTC
Permalink
Hello Rajesh,

I usually have my own: MyApp::REST which extends
package MyApp::REST;
use Moose;
use Try::Tiny;
use DBIx::Class::ResultSet::RecursiveUpdate;
use Scalar::Util qw( reftype );

BEGIN { extends 'Catalyst::Controller::DBIC::API::REST' }

with 'Iris::Web::TraitFor::Controller::Datatables';


.

and later on modifier:

=head2 list_format_output

Add more information about current search

=cut

after 'list_format_output' => sub {
my ($self, $c) = @_;

if (!$self->has_errors($c) && $c->req->has_search_total_entries) {
my $current_result_set = $c->req->current_result_set;

$c->stash->{ $self->stash_key }{last_page} = $current_result_set->pager->last_page + 0;
$c->stash->{ $self->stash_key }{current_page} = $current_result_set->pager->current_page + 0;
$c->stash->{ $self->stash_key }{entries_per_page} = $current_result_set->pager->entries_per_page + 0;
$c->stash->{ $self->stash_key }{entries_on_this_page} = $current_result_set->pager->entries_on_this_page + 0;
}
};
Best regards,
Post by Rajesh Kumar Mallah
Hi ,
We know that Catalyst::Controller::DBIC::API supports paging
via list_count , list_page and list_offset options and
its possible to fetch a page of a large result set.
However what it does not seems to support is to tell
the View(caller) of how many records in total exists , ie
the total_entries of the Data::Page object.
This compels us to make two queries one to get the total count
and another to get the paged result.
Does this feature really does not exists or am I missing something?
(The reason I love and thoroughly use Catalyst::Controller::DBIC::API is
that it allows me to be lazy :p )
regds
Rajesh Kumar Mallah.
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
Hartmaier Alexander
2017-03-23 11:15:31 UTC
Permalink
Hi,

it does return it in the totalcount property by default.

The name can be configured with the 'total_entries_arg' config parameter: https://metacpan.org/pod/Catalyst::Controller::DBIC::API#count_arg,-page_arg,-select_arg,-search_arg,-grouped_by_arg,-ordered_by_arg,-prefetch_arg,-as_arg,-total_entries_arg

Best regards, Alex

On 2017-03-19 18:38, Dimitar Petrov wrote:
Hello Rajesh,

I usually have my own: MyApp::REST which extends

package MyApp::REST;
use Moose;
use Try::Tiny;
use DBIx::Class::ResultSet::RecursiveUpdate;
use Scalar::Util qw( reftype );

BEGIN { extends 'Catalyst::Controller::DBIC::API::REST' }

with 'Iris::Web::TraitFor::Controller::Datatables';


.

and later on modifier:


=head2 list_format_output

Add more information about current search

=cut

after 'list_format_output' => sub {
my ($self, $c) = @_;

if (!$self->has_errors($c) && $c->req->has_search_total_entries) {
my $current_result_set = $c->req->current_result_set;

$c->stash->{ $self->stash_key }{last_page} = $current_result_set->pager->last_page + 0;
$c->stash->{ $self->stash_key }{current_page} = $current_result_set->pager->current_page + 0;
$c->stash->{ $self->stash_key }{entries_per_page} = $current_result_set->pager->entries_per_page + 0;
$c->stash->{ $self->stash_key }{entries_on_this_page} = $current_result_set->pager->entries_on_this_page + 0;
}
};

Best regards,


On Mar 19, 2017, at 09:28, Rajesh Kumar Mallah <***@redgrape.tech<mailto:***@redgrape.tech>> wrote:

Hi ,

We know that Catalyst::Controller::DBIC::API supports paging
via list_count , list_page and list_offset options and
its possible to fetch a page of a large result set.

However what it does not seems to support is to tell
the View(caller) of how many records in total exists , ie
the total_entries of the Data::Page object.

This compels us to make two queries one to get the total count
and another to get the paged result.

Does this feature really does not exists or am I missing something?

(The reason I love and thoroughly use Catalyst::Controller::DBIC::API is
that it allows me to be lazy :p )

regds
Rajesh Kumar Mallah.




_______________________________________________
List: ***@lists.scsys.co.uk<mailto:***@lists.scsys.co.uk>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




_______________________________________________
List: ***@lists.scsys.co.uk<mailto:***@lists.scsys.co.uk>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Rajesh Kumar Mallah
2017-03-29 10:05:16 UTC
Permalink
Thanks , It does return *when* paging related params are passed.
I have now used that result in my code.


Kind Regds
mallah.
Post by Hartmaier Alexander
Hi,
it does return it in the totalcount property by default.
https://metacpan.org/pod/Catalyst::Controller::DBIC::API#count_arg,-page_arg,-select_arg,-search_arg,-grouped_by_arg,-ordered_by_arg,-prefetch_arg,-as_arg,-total_entries_arg
Post by Hartmaier Alexander
Best regards, Alex
Hello Rajesh,
I usually have my own: MyApp::REST which extends
package MyApp::REST;
use Moose;
use Try::Tiny;
use DBIx::Class::ResultSet::RecursiveUpdate;
use Scalar::Util qw( reftype );
BEGIN { extends 'Catalyst::Controller::DBIC::API::REST' }
with 'Iris::Web::TraitFor::Controller::Datatables';
….
=head2 list_format_output
Add more information about current search
=cut
after 'list_format_output' => sub {
if (!$self->has_errors($c) && $c->req->has_search_total_entries) {
my $current_result_set = $c->req->current_result_set;
$c->stash->{ $self->stash_key }{last_page} =
$current_result_set->pager->last_page + 0;
$c->stash->{ $self->stash_key }{current_page} =
$current_result_set->pager->current_page + 0;
$c->stash->{ $self->stash_key }{entries_per_page} =
$current_result_set->pager->entries_per_page + 0;
$c->stash->{ $self->stash_key }{entries_on_this_page} =
$current_result_set->pager->entries_on_this_page + 0;
}
};
Best regards,
On Mar 19, 2017, at 09:28, Rajesh Kumar Mallah
Hi ,
We know that Catalyst::Controller::DBIC::API supports paging
via list_count , list_page and list_offset options and
its possible to fetch a page of a large result set.
However what it does not seems to support is to tell
the View(caller) of how many records in total exists , ie
the total_entries of the Data::Page object.
This compels us to make two queries one to get the total count
and another to get the paged result.
Does this feature really does not exists or am I missing something?
(The reason I love and thoroughly use Catalyst::Controller::DBIC::API is
that it allows me to be lazy :p )
regds
Rajesh Kumar Mallah.
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Post by Hartmaier Alexander
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.or

Loading...