Comments (7)
I'm not sure what do you mean. I've checked and everything seems to be fine.
Given such two modules:
defmodule X do
use Tesla
plug Tesla.Middleware.BaseUrl, "http://httpbin.org"
def new do
Tesla.build_client [
{Tesla.Middleware.Tuples, nil}
]
end
end
defmodule Y do
use Tesla
plug Tesla.Middleware.Tuples
def new do
Tesla.build_client [
{Tesla.Middleware.BaseUrl, "http://httpbin.org"}
]
end
end
iex(1)> X.get("/ip")
%Tesla.Env{url: "http://httpbin.org/ip", ...}
# only BaseUrl used
iex(2)> X.new() |> X.get("/ip")
{:ok,
%Tesla.Env{url: "http://httpbin.org/ip"}, ...}
# Both Tuples and BaseUrl used
iex(3)> Y.get("/ip")
{:error, %Tesla.Error{message: "adapter error: :no_scheme", reason: :no_scheme}}
# Only Tuples used, hence error since "/ip" is not a valid URL
iex(4)> Y.new() |> Y.get("/ip")
{:ok,
%Tesla.Env{url: "http://httpbin.org/ip", ...}}
# Both middlewares used
from tesla.
from tesla.
Ok, I was able to reproduce it, but I'm not convinced it's an error. Let me know what you think. I have something that looks like this:
defmodule Z do
use Tesla
plug Tesla.Middleware.Tuples
plug Tesla.Middleware.Headers, %{"User-Agent" => "MyConn", "Content-Type" => "application/json"}
def client(base_url) do
Tesla.build_client [
{Tesla.Middleware.BaseUrl, base_url}
]
end
end
client = Z.client("http://httpbin.org")
client |> Tesla.request(method: :get, url: "/ip")
|> IO.inspect
You'll notice that I am calling Tesla.request
instead of Z.request
. If I call the latter it works. The former does not.
I wanted a method that would allow me to specify requests as data and pass then very late to the execution method, so I sought out the request
method (method can be data). I found it in the Tesla module and didn't realize I should use my module to call it.
from tesla.
Yup, it works this way.
I think we could add something like "common mistakes" to readme. It's not first time when someone uses http functions directly from Tesla module 😢
from tesla.
from tesla.
Direct usage serves different purpose than generated module. For example when I want to check output of my own endpoint I run quick Tesla.get("http:://localhost:4000/api/something")
in iex. We should not threat this as something bad.
I'm still more convinced to readme/docs improvements. I just need more time to think about it.
from tesla.
Closing this for now, I'm not sure we can do much about it.
from tesla.
Related Issues (20)
- G
- Document the need for telemetry in the mix file HOT 3
- Mint proxy credentials HOT 1
- Issues Working with QuotaGuard QGTunnel HOT 3
- [Proposal] Lower the usage of macros HOT 2
- Setting retry delay on runtime. HOT 1
- Telemetry metadata doesn't have data about response in case of error
- Dialyzer failing on Tesla (master) HOT 3
- Tesla Response Stream is not compatible with Tesla Multipart upload
- Jason.Encoder protocol must always be explicitly implemented HOT 1
- Be more explict on `:no_scheme` error reason HOT 1
- When setting the adapter on runtime, mocking does not work
- Logger debug: true does nothing at runtime HOT 2
- Compiler warnings with Elixir v1.17.0-rc.0 HOT 3
- Tesla.Multipart.assert_part_value! doesn't allow valid stream
- Content type should be case insensitive HOT 2
- Tesla.Mock.pdict_get/0 doesn't work inside of Broadway HOT 3
- Test failures and compiler warnings in Elixir 1.16 (httparrot) HOT 6
- Tesla 1.9.0+ is not compatible with Elixir 1.10 HOT 2
- Versions 1.9 and later changed the return value for a Mint.TransportError in Tesla.Adapter.Finch.call/2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tesla.