yordisprieto

yordisprieto

Tesla is an HTTP client that leverages middleware to streamline HTTP requests and responses over a common interface for various adapters.

It simplifies HTTP communication by providing a flexible and composable middleware stack. Developers can easily build custom API clients by stacking middleware components that handle tasks like authentication, logging, and retries. Tesla supports multiple HTTP adapters such as Mint, Finch, Hackney, etc.

Tesla is ideal for developers who need a flexible and efficient HTTP client. Its ability to swap out HTTP adapters and create custom middleware pipelines empowers you to make different architectural decisions and build tools tailored to your application’s needs with minimal effort.

Inspired by Faraday from Ruby.

https://github.com/elixir-tesla/tesla


Please check Tesla’s latest documentation update at Tesla — tesla v1.20.0.

I would appreciate any feedback about it. I need a different perspective to make sure the documentation covers most personas. The In-Module documentation is still WIP; I focused on guides and the getting started experience.

Showing Posts 1 to 7

yordisprieto

yordisprieto OP

Tesla v1.13 introduces Tesla.Test module and direct integration with Mox You can read more about How-To at Test Using Mox — tesla v1.20.0

yordisprieto

yordisprieto OP

bgoosman

bgoosman

I’ve been using Req mostly. How would you compare Req to Tesla?

yordisprieto

yordisprieto OP

I use both; it all depends.

Req is excellent for getting something working very fast. At the same time, I use Tesla for predictable SDKs since Tesla barely includes anything by default, and Tesla has been around and used in production quite a bit.

You can check the built-in steps/middleware and the defaults you like; to me, they are the same, just different starting points.

adamu

adamu

For me Tesla.Middlewear.Logger is great for debugging as you can log the whole request/response. I believe the architecture of Req makes this difficult as there is no way to hook into the entire communication cycle.

I also find that the Tesla Middlewear model is simpler than Req’s, which requires more boilerplate and is a bit harder to get your head around, at least that was my impression from writing equivalent middlewear for both clients:

Tesla:

    def call(%Tesla.Env{method: :get, url: url} = env, next, options) do
      timeout = Keyword.get(options || [], :debounce_timeout)

      case Boing.debounce(url, timeout) do
        :ok -> Tesla.run(env, next)
        {:error, debounced: ^url} -> {:error, debounced: url}
      end
    end

Req:

    defmodule DebouncedException do
      defexception [:url]

      @impl Exception
      def message(%__MODULE__{url: url}), do: "Debounced: #{url}"
    end

    def attach(%Req.Request{} = request, options \\ []) do
      request
      |> Req.Request.register_options([:debounce_timeout])
      |> Req.Request.merge_options(options)
      |> Req.Request.append_request_steps(debounce: &debounce_step/1)
    end

    defp debounce_step(%Req.Request{method: :get, url: url} = request) do
      timeout = request.options[:debounce_timeout]

      case Boing.debounce(URI.to_string(url), timeout) do
        :ok -> request
        {:error, debounced: url} -> {request, DebouncedException.exception(url: url)}
      end
    end

pau-riosa

pau-riosa

Hi guys, how can I consume a stream from a get request using Tesla?
I am using Tesla.Adapter.Finch and wanted to consume an audio/wave file using stream.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New

Other Trending Topics Top

KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews