Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Adding simple HTTP controls to existing code

by Corion (Patriarch)
on Jul 05, 2021 at 11:40 UTC ( [id://11134664]=note: print w/replies, xml ) Need Help??


in reply to Adding simple HTTP controls to existing code

For example, the two web frameworks Mojolicious and Dancer (or Dancer2), or maybe even the raw Plack interface allow you to do that, and they each come with a built-in web server as well.

Your program could look like the following, adapted from the Mojolicious::Lite synopsis:

# Automatically enables "strict", "warnings", "utf8" and Perl 5.16 f +eatures use Mojolicious::Lite -signatures; # Route with placeholder get '/' => sub ($c) { my $foo = $c->param('foo'); $c->render(text => "Hello from $foo."); run_main_program(); }; # Start the Mojolicious command system app->start;

Replies are listed 'Best First'.
Re^2: Adding simple HTTP controls to existing code
by brachism (Novice) on Jul 05, 2021 at 12:55 UTC
    Thanks, I will look those up, though I’d hoped to avoid adding dependencies on any large packages or frameworks for something seemingly trivial. As my core code repeats multiple times a second, I wonder if it might be easier just to open a socket, and managed it directly, polling for data, and deal with traffic. Thanks again.
      Then Mojo is your thing. It only has two dependencies, both of which are Core.


      holli

      You can lead your users to water, but alas, you cannot drown them.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found