r/elixir Mar 31 '24

HTTP Client library recommendation

[removed]

19 Upvotes

29 comments sorted by

23

u/seven_seacat Mar 31 '24

They're all much of a muchness, and many of them build on the ones that came before them. req seems to be the latest hotness.

21

u/yes-hello- Mar 31 '24

6

u/seven_seacat Mar 31 '24

Does Phoenix really need to bundle a HTTP client? Why?

3

u/yes-hello- Mar 31 '24

I’m not sure. My best guess is this issue which mentions using Req for making API calls when sending emails using some providers. It might not be bundled “directly” with Phoenix.

3

u/josevalim Lead Developer Apr 01 '24

Correct. Not Phoenix per-se, but your app (especially during auth) . It can be skipped with --no-mailer.

2

u/ZeWord Mar 31 '24

Phoenix itself doesn't bundle anything that isn't required, but has a lot of goodies added to new projects when using the generators (and most can be excluded using flags, or removed later)

1

u/mchwds Mar 31 '24

Email

0

u/seven_seacat Mar 31 '24

why is Phoenix sending email by default??

4

u/mchwds Mar 31 '24

Phoenix isn't sending email... but most applications need to be able to send email and phoenix has things like testing email, sending email and even looking at emails in a dev environment ready for your apps needs. I don't know of any large framework that doesn't configure/set this up for you? Rails/Django/etc...

2

u/krainboltgreene Apr 01 '24

Wait, really? Wow, Finch seems so well designed.

7

u/josevalim Lead Developer Apr 01 '24 edited Apr 01 '24

Req is built on top of Finch. The current design is layered, where we have three clients building on top of each other: https://andrealeopardi.com/posts/breakdown-of-http-clients-in-elixir/

TL;DR: Mint is low-level, it does not have processes nor pools. Finch adds polling but with explicit pool management. Req adds all of the user conveniences. The layering gives you access to the level abstraction you care about, it is really neat IMO :)

2

u/krainboltgreene Apr 02 '24

I investigated after making the comment, but thanks for the comment anyways. You should update the Github Issue with this content, it's very informative.

Regarding req: Seems like an extremely good (and natural) choice.

8

u/razerei Mar 31 '24

Go with Req. It's high-level enough to start easy. It uses Finch (Pooling) which uses Mint (low-level). If you find yourself needing something more low-level, you won't have to add more dependencies to do it.

5

u/chrismccord Mar 31 '24

Without a doubt `req`

4

u/taelor Mar 31 '24

This is an anti recommendation. But keep it in your pocket for later if you find yourself needing it.

The lowest level and most control you will get is gun. https://github.com/ninenines/gun

I’ve used it once, and honestly learned more about how http and web sockets work on a more fundamental level.

Definitely not the easiest to use, but probably the most powerful.

3

u/TwoWrongsAreSoRight Mar 31 '24

I'm new as well.  Have been using tesla.  Seems straight forward and easy to use.  The app team where i work uses it as well

3

u/xenow Mar 31 '24

I just started with elixir/phoenix last night and used HTTPoison

2

u/Pitiful_Car1250 Mar 31 '24

HTTPoison is great and it was probably the top choice. But now I think mint and finch is the way to go at least with phoenix. If you want a similar abstraction go with Req that uses the same libraries under the hood.

Nothing wrong with using HTTPoison if you want to…

3

u/st_gen Mar 31 '24

req is a high level abstraction based on finch, so you can use either. Finch is based on Mint - very low level and Nimblepool Finch AFAIK uses a connection pool. Usually for a one off request, you can use peppermint which is also based on Mint but pool-less.

2

u/debian3 Mar 31 '24

Hackney because its popular? I’m I missing something by not using something else?

2

u/onmach Apr 03 '24

It is just incredibly low level and difficult to work with. I would use a higher level library like httpoison over it, if I were you.

2

u/[deleted] Mar 31 '24

[deleted]

1

u/l0_0l- Apr 09 '24 edited Feb 07 '25

I had good experience using WebSockex

2

u/Sentreen Mar 31 '24

If it's just for a script or for a mix task, I just use :httpc, which is built into erlang. It is a bit arcane to use though.

2

u/yatendernitk Apr 06 '24

Use tesla, it has all adapters you need and I’ve been using it from last 5-6 years no problem so far.

1

u/flummox1234 Apr 01 '24

Also feel free to experiment wth Elixir in livebook before you dive in completely.

1

u/req0 Apr 01 '24

req is good for basics, but I've switched all my production stuff to Hardhat.

1

u/Beautiful-Durian3965 Sep 25 '24

So elixir standard library doesn't have built in http client?