Perl/Raku succinct webserver one-liner?

Viewed 209

Are there any concise one-liners for quick serving of pages or directories if no index.html? Something like this:

python3 -m http.server

Couldn't find a Raku one-liner.
Compare Perl ones, taken from https://gist.github.com/willurd/5720255 and https://github.com/imgarylai/awesome-webservers :

plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000
perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'

Install them prior to use (no additional installs with Python):

cpan Plack
cpan HTTP::Server::Brick

Plack pulls in a gajillion of dependencies so I didn't proceed with installation, and HTTP::Server::Brick doesn't install on my machine as its tests fail.

Both Perl and Raku are generally considered to be good in one-liners, and are meant to deliver DWIM: "try to do the right thing, depending on the context", "guess ... the result intended when bogus input was provided"

So I'd expect them - especially modern and rich Raku - to provide a webserver one-liner on par in simplicity with Python.
Or have I missed something?
If the feature lacks, is it planned?
If lacks and not-to-be-implemented, why?

3 Answers

I like http_this (https_this is also available).

There's an annoying shortcoming in that it doesn't currently support index.html - but I have a pull request pending to fix that.

On the other hand, these programs rely on Plack, so maybe you'd rather look elsewhere.

Raku Cro needs one line to install:

zef install --/test cro

And then one to setup and run:

cro stub http hello hello && cro run

From https://cro.services/docs/intro/getstarted

Let's say you want to serve all the files in a project subdirectory e.g. hello/httpd, then tweak the standard hello/lib/Routes.pm6 file to this:

  1 use Cro::HTTP::Router;
  2 
  3 sub routes() is export {
  4     route {
  5         get -> *@path {
  6             static 'httpd', @path;
  7         }
  8     }
  9 }

cro run looks for file changes and will auto restart the server

index.html works fine

I suggest a symbolic link ln -s if your dir is outside the project tree

Putting aside the webserver portion of your question, Python and Perl differ in their philosophies. Both of them are perfectly fine ways of doing things, and each appeals to a different sort of crowd.

  • Python is "batteries included", so it's a heavyweight distribution of many things in its standard library. There's more right out of the box, even if you never use most of it.
  • Perl tries to distribute just enough for you to install the modules that you decide that you need. That way, you can choose something that is fresher or newer than the thing that Perl chose to distribute.

Now, for the webserver, you may like Mojolicious. It's mostly self-contained (or relies on mostly core modules) so it's an easier install. The links you mentioned have Mojolicious::Lite examples.

Related