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.

dimitarvp

dimitarvp

No, not at all. Modules are loaded just fine but there is the concept of applications that start various OTP processes which is achieved by the applications themselves being “started” (“application” being a useful abstraction here).

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
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

We're in Beta

About us Mission Statement