c4710n

c4710n

Background

When implementing libraries which have to sent HTTP/HTTPS requests, we have to implement an HTTP client.

In most of time, people implement their own HTTP client with their preferred underlying library, such as: httpc, hackney, mint, finch, etc.

But, maybe that’s not the good way.

Doing so not only wastes the time but also makes the libraries inflexible. If using multiple libraries, and these libraries use different HTTP clients, we will have many different implementations of HTTP clients running at the same time.

What’s the big deal?

Using multiple implementations of HTTP clients in one project, not only consumes more resources but may also creates inconsistencies in usage patterns, complicates maintenance, observation and debugging, etc.

It would be good if we can have a unified HTTP implementation, and then each library author can use it. In the way:

  • every library author can add multiple HTTP-adapters support in short time.
  • every library user can choose their preferred HTTP client in a flexible way.

What to use?

After investigating existing HTTP implementations, I found elixir-tesla/tesla, which considers what I said above.

Tesla provides a very flexible way to configure adapters. Let’s say we want use hackney as the adapter.

  1. Set an adapter at module level in the module itself:
defmodule GitHubClient do
  use Tesla

  adapter Tesla.Adapter.Hackney, recv_timeout: 30_000

  # ...
end
  1. Set an adapter at module level in the config file:
config :tesla, GitHubClient, adapter: {Tesla.Adapter.Hackney, [recv_timeout: 30_000]}
  1. Set an adapter at app level in the config file (this is not supported for now, but I have created an PR for it):
config :tesla, :my_app, adapter: {Tesla.Adapter.Hackney, [recv_timeout: 30_000]}
  1. Set an adapter at global level in the config file:
config :tesla, adapter: {Tesla.Adapter.Hackney, [recv_timeout: 30_000]}

Last

Everyone can benefit from using Tesla:

  • every library author can add multiple HTTP-adapters support in short time.
  • every library user can choose their preferred HTTP client in a flexible way.

Consider using it when writing your next package. If you do, remember to include a badge in your README.md, like Tesla compatible.

[![Tesla compatible](https://img.shields.io/badge/Tesla%20compatible-6e4a7e?Color=white)](https://github.com/elixir-tesla/tesla)

That’s it. :wink:

Showing Posts 1 to 3

mruoss

mruoss

@whatyouhide also discussed this topic in his blog post “A Breakdown of HTTP Clients in Elixir”. Me personally, as a library author I’d rather use Req than Tesla. It also allows for custom HTTP adapters. The problem I have with Req (for libraries) is that its default adapter (Finch) is not an optional dependency which, in the case of libraries, would be desirable.

The “adapter behaviour” Andrea discusses in the blog post is a possible approach for libraries. But as a library author, I don’t want to give up on the conveniences I get from req (steps) or tesla (middlewares). I’m in a bit of a dilemma here… :slight_smile:

c4710n

c4710n OP

Previously, I think that req and finch are tightly bound. If, as he says, finch will also support multiple adapters and offer flexible configuration options, that would be terrific.

Thank you for refreshing my understanding. :wink:

Maybe, someday, it would be Req-compatible libraries.

mruoss

mruoss

Edit: sorry, misread your post

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews