Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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)];


Comment on Re: Preferred RPC method?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2014-07-29 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls