Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Preferred RPC method?

by Rhandom (Curate)
on Jul 02, 2009 at 13:52 UTC ( #776750=note: print w/replies, xml ) Need Help??

in reply to Preferred RPC method?

I've done SOAP and many many custom XML interchanges. They are all either fairly cumbersome or they just feel heavy. Ninety-five percent of the time now I just use JSON. It is easy to add to any Catalyst, CGI::Appliation, CGI::Ex::App, or whatever type application.

sub json_run_step { my $self = shift; my $form = $self->form; my $type = $form->{'type'}; my $data; my $ok = eval { die "Invalid type \"$type\"\n" if $type !~ /^[a-z]\w+$/; die "Invalid method \"$type\"\n" if ! $self->can($type); $data = $self->$type($form); }; if (! $ok) { $data = { error => "$@" || "An error occurred", }; } $self->cgix->print_content_type('application/x-javascript'); print JSON::to_json($data)."\n"; return 1; }

With JSON, my exposed methods are easily available to other perl scripts, or more importantly, they are available to my javascript applications (AJAX isn't quite the word here as the "Asychronous" and "And XML" don't apply in many of my scripts - so all you are left with is the the J".

I know that this sort of solution doesn't include parameter checking, but normally my methods include any of the bounds checking that I may need.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://776750]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2020-09-28 14:28 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (143 votes). Check out past polls.