Comments (4)
Hi!
Can you show an example of your code? I don't think we can skip the %Tesla.Client{}
match since this is the way we can achieve current api - get/2 (path, opts)
vs get/2 (client, path)
from tesla.
To clarify, the point of this wouldn't be to skip the %Tesla.Client{}
match, it would be to allow you to modify that match to use a different struct name, so that different get/2
functions in different modules that both use Tesla
will refuse to use each-other's clients.
Currently, this works fine, because APITwo.get/2
matches on %Tesla.Client{}
returned by APIOne.client
:
defmodule APIOne do
use Tesla
def client do
Tesla.build_client [
{Tesla.Middleware.Headers, %{"Authorization" => "token: " <> token }}
]
end
end
defmodule APITwo, do: use Tesla
APITwo.get(APIOne.client, "foo")
My proposal is to allow Tesla to generate client structs 'private' to a particular invocation of use Tesla
, such that:
defmodule APIOne do
use Tesla, client: APIOne.Client
def client do
APIOne.Client.build [
{Tesla.Middleware.Headers, %{"Authorization" => "token: " <> token }}
]
end
end
defmodule APITwo, do: use Tesla, client: APITwo.Client
APITwo.get(APIOne.client, "foo")
raises:
** (FunctionClauseError) no function clause matching in APITwo.get/2
The following arguments were given to APITwo.get/2:
# 1
%APIOne.Client{...}
# 2
"foo"
iex:1: Foo.bar/1
Because, since APIOne
's use Tesla
was given a client struct name, it generated a client struct with that name (%APIOne.Client{}
) , and because APITwo
was also given a client struct name, it generated a APITwo.get/2
that is matching on that specific struct (%APITwo.Client{}
) instead of any old %Tesla.Client{}
.
from tesla.
Here, this is kind of what I was envisioning.
from tesla.
Closing in favour of #133
from tesla.
Related Issues (20)
- Fuck you HOT 2
- 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
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.