Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Preferred RPC method?

by Rhandom (Curate)
on Jul 02, 2009 at 13:52 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found