Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

LWP::Simple vs HTTP::Tiny

by Bod (Parson)
on Dec 13, 2020 at 12:46 UTC ( [id://11125103]=perlquestion: print w/replies, xml ) Need Help??

Bod has asked for the wisdom of the Perl Monks concerning the following question:

In the past I've always used LWP::Simple when I've needed to fetch something from a web server or pass some information by way of the query string. Basically anytime I've not needed the full power of LWP::UserAgent.

Only recently I learnt of HTTP::Tiny which appears to do more than LWP::Simple including being able to set the User Agent string and supporting mirrors. It is also core.

This would make me think that I should drop using LWP::Simple and start using HTTP::Tiny instead. However, on my laptop which has both modules installed, CPAN uses LWP::Simple whereas on the Raspberry Pi, CPAN uses HTTP::Tiny. Given the choice CPAN makes, implies that LWP::Simple is somehow better...

Are there any advantages for making simple web requests of using one over the other or does it come down to personal preference?

Replies are listed 'Best First'.
Re: LWP::Simple vs HTTP::Tiny
by Discipulus (Canon) on Dec 13, 2020 at 13:20 UTC
    Hello Bod (and my even if late, warmest welcome to the monastery!)

    In my opinion if there is something in core, use it. HTTP::Tiny has been in core since 5.14

    I suppose cpan client can use different http clients, but I never investigated this.

    The author of HTTP::Tiny wrote a nice introduction with comparisons too: why HTTP::Tiny

    Back in time we had only LWP::* modules to use and many of us used them a lot. Nothing bad to still using them as they still work great. But there are many and newer and better nowadays: Mojo::UserAgent is worth a mention among them.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Hello Bod (and my even if late, warmest welcome to the monastery!)

      Thank you very much indeed - I certainly feel welcomed by many long standing, esteemed Monks. Joining in rather than just observing occasionally is something I should have done a long, long time ago and I strongly wonder why I didn't whilst at the time speculating how much improved by Perl and general coding skills would be had I joined many years ago!

      The author...wrote a nice introduction with comparisons too: why HTTP::Tiny

      Thank you. I had already read that and it compares HTTP::Tiny to the full blown LWP::UserAgent. I totally understand the need for a smaller HTTP module which LWP::Simple provides.

      It was CPAN's choice of HTTP module which confuses me when it has the option of both, it prefers LWP::Simple.

        I totally understand the need for a smaller HTTP module which LWP::Simple provides.

        Just in case you were unaware, LWP::Simple is just a wrapper around LWP::UserAgent. The "Simple" refers to the simplified interface only. In using LWP::Simple instead of LWP::UserAgent you are actually consuming more RAM, not less and loading more modules, not fewer.

        Update: Edited for clarity.


        🦛

Re: LWP::Simple vs HTTP::Tiny
by marto (Cardinal) on Dec 13, 2020 at 13:18 UTC

    Firstly, if you are building from source rather than using OS package management on the pi use cpanm over cpan. It makes a big difference on systems with a small memory footprint. What do you mean "better"? why httptiny.

Re: LWP::Simple vs HTTP::Tiny
by stevieb (Canon) on Dec 13, 2020 at 16:14 UTC
    "Are there any advantages for making simple web requests of using one over the other or does it come down to personal preference?"

    It's always developer preference, but what dictates that preference is what matters. Which one is more compact, requiring the fewest number of dependencies? Is one of them core and the other isn't? Does the smallest, lightest one do everything I want it to do? Is it maintained regularly? Does it appear that the authors are responsive, dealing with issues in a reasonable time frame?

    I mean for example: Both do what I need them to do. One is in core, the other isn't. One requires Moose and the other doesn't. etc, etc etc.

    Look at the future of your project. Do you predict that you'll need features eventually that is in one distribution, but not the other?

      To this I’ll add, which one has the better API? Is it easy to do what you want or is it clunky? After all, computer time is cheaper than programmer time and “Premature optimization is the root of all evil”.
Re: LWP::Simple vs HTTP::Tiny
by 1nickt (Canon) on Dec 13, 2020 at 23:12 UTC

    LWP::UserAgent is full-featured but slow. HTTP::Tiny follows the ::Tiny design rules and offers almost all the same functionality in a much lighter faster package. Furl is even faster.

    When building high-use API clients I choose between full-featured and really fast. For everything else (scripts, low-use clients, etc.) I use the core module.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: LWP::Simple vs HTTP::Tiny
by salva (Canon) on Dec 14, 2020 at 10:01 UTC
Re: LWP::Simple vs HTTP::Tiny
by perlfan (Vicar) on Dec 14, 2020 at 19:48 UTC
    HTTP::Tiny is included in core, but SSL support is not "on" by default because it requires Net::SSLeay and IO::Socket::SSL. I personally find HTTP::Tiny easier to use, but loads of modules require LWP. LWP also supports other protocols, such as gopher (which like perl and BSD is dead/dying xD). So LWP is still very much relevant. If I were writing a client for a REST API (e.g.,) I would be using HTTP::Tiny. I have not looked at some other other suggestions, but they may suite your needs better - so YMMV.
      but SSL support is not "on" by default

      Yes, I found this out.
      It has also been impossible so far to install the required modules as it gives errors. Not just with these modules but with everything I've tried to install on the RPi from CPAN.

      I will solve this problem but for now I've created a subdomain on my website without SSL just for this project to get its updates. Doing that and only using core modules has allowed me to get everything working.

        "It has also been impossible so far to install the required modules as it gives errors. Not just with these modules but with everything I've tried to install on the RPi from CPAN." if you're going to start a thread about this, please provide sufficient details.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11125103]
Approved by Discipulus
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found