henriquesati

henriquesati

** (ArgumentError) unknown registry: Req.Finch on a simple http request using Req library

I’m doing a POST request using Req but i’m getting the error ** (ArgumentError) unknown registry: Req.Finch. I found the same problem on elixir reddit but I couldnt manage to understand and apply the possible solution
My code:

defmodule GetPayloadInfo do

  def doReq do
    token = "XXX"
    req = Req.Request.new(method: :post, url: "https://sandbox.asaas.com/api/v3/pix/qrCodes/decode")
    req = Req.Request.put_headers(req, [{"accept", "application/json"}, {"acess_token", token}, {"content-type", "application/json"} ])

    {req, resp} = Req.Request.run_request(req)
  end

end

Then I simply call the function on my main file with a simple hello world output so make sure its all fine before this

Hello.say_hi()
GetPayloadInfo.doReq()

and this is my mix.exs file

defmodule TestesPay.MixProject do
  use Mix.Project

  def project do
    [
      app: :testes_pay,
      version: "0.1.0",
      elixir: "~> 1.16",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      telemetry: [enabled: false],
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:req, "~> 0.5.0"}
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
    ]
  end
end
the code contains no scripts, only .ex files, located at lib

Most Liked

LorenzoD

LorenzoD

For those finding this thread after running into this error when using Req in a function within a Mix.Task module: This problem is resolved by adding @requirements ["app.start"] at the module level. This ensures that Req and its dependencies are available for use when you execute the Mix task.

More information can be found in the documentation here.

wojtekmach

wojtekmach

Hex Core Team
== Compilation error in file lib/cry.ex ==

Oh, you’re using Req at compile-time, i.e. in module body and similar. In that case it seems you need to explicitly start dependencies:

defmodule Foo do
  {:ok, _} = Application.ensure_all_started(:req)
  Req.get(...)
end
wojtekmach

wojtekmach

Hex Core Team

compile-time vs runtime is a pretty broad topic so to just scratch the surface when you have a module:

def Foo do
  IO.puts :at_compile_time

  def foo do
    IO.puts :at_runtime
  end
end

the first IO.puts is executed while the module is being compiled. When it is being used at runtime, that IO.puts will not be executed. On the other hand, the second IO.puts is NOT executed when the module is being compiled. It is only executed when you call Foo.foo(). Doing things at compile-time is definitely an Elixir super power and for this particular use case you need that Application.ensure_all_started. (The reason is Req library starts a supervision tree in its application callback module. If it didn’t, ensure_all_started would not be necessary.) In vast majority of day to day Elixir programming, you don’t need ensure_all_started, it is done for you.

Where Next?

Popular in Questions Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement