News for hackers. Stuff that matters.
Re:Httpx: A Ruby HTTP library by 0xFACEFEED on Wednesday October 30, 2019 @04:50AM (#21395684)
Never understood why people prefer APIs like this:

  page1, page2, ... = HTTPX.get("/page1", "/page2", ...)
Why encode parallelism into a single polymorphic function? Why not use composition instead? Now you're stuck with this API forever. And if you want to customize parallel fetches (eg: batching) you'll need another different looking API.
Re:Httpx: A Ruby HTTP library by chucke on Wednesday October 30, 2019 @05:29AM (#21395882)
Hi, I maintain httpx. I'll try to answer your concerns.

The API was not a question of preference. If you look at most http lib APIs (python requests included), a single call returns a response object. My goal was to keep compatibility with this API to ease the migration effort, while baking in support for concurrent requests, which was the whole point of the lib.

There is no parallelism in that call btw. It's in the Readme. If it's http/2, it'll multiplex requests. If it's http/1, it'll try to pipeline, and if doesn't work, it'll fetch them one by one (with or without keep-alive). If they're different origins, the requests will be managed inside an event loop.

> Why not use composition instead?

You'll have to explain with an example of your own. However, there's already a ticket for implementing an event-based request handling, I just never prioritized it because no one asked for it yet, no one has shown interest in contributing, and frankly, I haven't needed it yet.

> Now you're stuck with this API forever.

It's still early 0.x days, so I might still remove APIs I don't think are future proof. That said, a lot of libs have lived with similar APIs all these years, and I don't see any reason for removing it.

Re:Httpx: A Ruby HTTP library by michaelbuckbee on Wednesday October 30, 2019 @08:24AM (#21396889)
Hey, very impressed with httpx. I'm not in a spot to contribute code but would like to sponsor (if that's an option). My email's in my HN profile and apologies for dropping this into the thread I couldn't find contact info elsewhere.
Re:Httpx: A Ruby HTTP library by chucke on Wednesday October 30, 2019 @12:26PM (#21399446)
Thx for the kind words. I thank, but will not accept financial contributions from individuals. Feel free to use it, modify it, or talk about it to your colleagues :)
Re:Httpx: A Ruby HTTP library by maximegarcia on Wednesday October 30, 2019 @12:24PM (#21399427)
Nice lib, eager to use it in replacement of HTTP.rb, auto managed persistent connection is a great addition.

Do you plan to support webmock and httplog ? Or add support for httpx into those ?

Can't integrate a networking lib that can't be mocked in my specs.

Re:Httpx: A Ruby HTTP library by chucke on Wednesday October 30, 2019 @08:05PM (#21404401)
Thx! I don't have any plans to integrate them, as I don't use any of them. But it should be trivial to create a plugin for them using the httpx plugin system: https://honeyryderchuck.gitlab.io/httpx/wiki/Custom-Plugins , feel free to give it a try.

httpx also ships with its own request/response logger, set HTTPX_DEBUG=1 or set the options so that you see an example.

Re:Httpx: A Ruby HTTP library by jbverschoor on Wednesday October 30, 2019 @08:08AM (#21396769)
Superb syntactical sugar.
Re:Httpx: A Ruby HTTP library by sudhirj on Wednesday October 30, 2019 @07:09AM (#21396389)
> It's still early 0.x days

Any idea why the project is posted now? Is there a beta or RC release that’s significant?

Re:Httpx: A Ruby HTTP library by bovermyer on Wednesday October 30, 2019 @09:19AM (#21397340)
My guess is that someone found it interesting and worth sharing with the HN community.
Re:Httpx: A Ruby HTTP library by pmontra on Wednesday October 30, 2019 @05:30AM (#21395888)
Do you mean, that vs something like this?

    responses = HTTPX.get("/page1").
                      get("/page2").
                      start
My guess is that the focus of HTTPX being parallel requests, the author choose an API that explicitly groups them together. The documentation is pretty sparse, I wonder if we can pass an array of URLs to get().
Re:Httpx: A Ruby HTTP library by fouc on Wednesday October 30, 2019 @06:53AM (#21396296)
yes, ruby has a splat * operator that will basically expand an array into a set of arguments.

    array = ["https://news.ycombinator.com/news", "https://news.ycombinator.com/news?p=2", "https://news.ycombinator.com/news?p=3"]

    page1, page2, page3 = HTTPX.get(*array)
Re:Httpx: A Ruby HTTP library by stormbrew on Wednesday October 30, 2019 @02:38PM (#21401003)
Note you can also splat the return as well:

    *pages = HTTPX.get(*urls)
Re:Httpx: A Ruby HTTP library by lloeki on Wednesday October 30, 2019 @06:53AM (#21396300)
splat?

   urls = ['https://example.com/foo', 'https://example.com/bar']
   HTTPX.get(*urls)
Re:Httpx: A Ruby HTTP library by cranej on Wednesday October 30, 2019 @05:05AM (#21395761)
And I guess it won't return unless all pages are fetched? even worse...
Re:Httpx: A Ruby HTTP library by chucke on Wednesday October 30, 2019 @05:31AM (#21395890)
There are timeouts involved, that is, you'll get error responses. Feel free to try the example scripts.
Re:Httpx: A Ruby HTTP library by cranej on Wednesday October 30, 2019 @09:43PM (#21404915)
> ...while baking in support for concurrent requests...

Timeout does not help here - if the api is for concurrent requests, it's bad that caller cannot do anything before `(the slowest request finished || timeout exceeded)`.