Comments (10)
Any update on this issue?
Tesla seems to have updated the api, so one could pass the adapter options directly now Tesla.client(middleware, adapter)
. But this is still not exposed by GoogleApi.Gax.Connection
.
We are currently working around the issue by configuring the adapter globally. But we really would like to avoid global config, as this means we can't use different adapter configs (like no proxy for internal services) for different client.
config :tesla,
adapter: {Tesla.Adapter.Hackney, [pool: Client.BigQuery, proxy: {host, port}]}
from elixir-google-api.
Thanks Jose for the great suggestion!
Defining the connection API seems like an easy step to take. We picked Tesla for it's extensibility and multipart request handling but we're not doing a great job of surfacing it. We'd also like to make Tesla an implementation detail of the default connections (but document how to extend it). Currently, Tesla structs bleed out into the developers' code.
from elixir-google-api.
Great! I have also opened two issues on Tesla, in case you'd rather expose it: elixir-tesla/tesla#218 and elixir-tesla/tesla#219
from elixir-google-api.
DISCLAIMER: I'm obviously biased here
The way I've always imagined client libraries build around tesla is that they expose a way to pass a custom %Tesla.Client{}
to add/change functionality (like fuse/timeout/retry/headers/adapter/etc).
If you need a dynamic client you could do something like:
# MyApi
def new(token, middleware \\ []) do
Tesla.build_client([{Tesla.Middleware.Header, "Bearer #{token}"}] ++ middleware)
end
# app code
client = MyApi.new(token, my_custom_middleware)
MyApi.some_function(client)
So, instead of hiding tesla it is actually exposed as first-class citizen and out of the box compatible with 3rd party tesla extensions. For example, need caching? - plug in tesla_cache middleware into your custom client.
I agree tesla docs are not the best currently but we are working on them! ( elixir-tesla/tesla#228 )
from elixir-google-api.
@teamon this would be a valid approach as long as everything in Tesla can be done at runtime. Middleware are fine. However, you can't configure adapters at runtime, which is the reason why I opened this issue and the ones in Tesla.
The only way to make the adapter customizable with the current Tesla version would be if Google API added a global compile time configuration.
The other limitation is that it is unclear how to customize the adapters in Tesla. So if I need to tune hackney, I need to figure out how to go all the way from Google API -> Tesla -> Hackney, and that's not easy. As long as one of those contracts are well defined (Google API -> HTTP client) or (Tesla -> HTTP client), then we should be good to go.
from elixir-google-api.
You can override adapter in runtime, but it's not pretty and it needs to be improved a lot.
iex(1)> Tesla.get("https://httpbin.org/ip")
{:ok, %Tesla.Env{status: 200, ...}}
iex(2)> client = Tesla.build_adapter(fn env -> IO.inspect("Custom adapter") end)
iex(3)> Tesla.get(client, "https://httpbin.org/ip")
"Custom adapter"
# no request has been made
(Adapter is just the last middleware that does not call Tesla.run
)
Regarding adapter customization - docs docs docs + best practices/tips & tricks
from elixir-google-api.
@teamon build_adapter
has no documentation. So it is unclear if it is a private function that was accidentally public or something that is meant to be used. build_adapter
also does not receive the client as argument, so I still unclear how to change the adapter of an existing client, which is likely what I would expect here.
In any case, the lack of documentation around those customizations are precisely what those issues are about. :) Given Tesla defaults to httpc, which I don't recommend for production usage, I would say replacing and customize adapters should be more prominently featured.
from elixir-google-api.
Yes, yes, and yes, all you say is (unfortunately) true.
Thanks for starting the discussion around it! I hope we can get it solved in the near future.
from elixir-google-api.
@ananthakumaran & others, you can specify a particular client for which the config applies. For example, for the DialogFlow client:
config :tesla, GoogleApi.Dialogflow.V2.Connection,
adapter: {Tesla.Adapter.Hackney, [pool: :dialogflow]}
from elixir-google-api.
Currently found this issue when trying to define a new middleware for the Tesla client like adding the Tesla.Middleware.Timeout. Interested to see if that's possible in another way and/or the state of this issue.
from elixir-google-api.
Related Issues (20)
- WigWamWoodys HOT 1
- The task "google_apis.auth" could not be found HOT 3
- elixir-google-api broke with latest gcloud pub/sub emulator 0.7.1
- Speech: support v1p1beta1 HOT 2
- The Hex Docs are not being built HOT 2
- STOP GENERATING THOUSANDS OF MODULES!!! HOT 7
- Recommend configuration of Tesla adapter in README
- Copying Object in GCS
- Retail version does not match the doc HOT 5
- google_api_play_integrity package is not available on hex.pm HOT 1
- Version 0.25.0 of `dfa_reporting` is missing on hex.pm
- Unclear attribute, transaction, for GoogleApi.Firestore.V1.Model.CommitRequest
- Is this still being maintained? HOT 1
- Synthesis failed for IDS HOT 33
- Is the new Google Identity's API available in this library? HOT 1
- GoogleCloudMlV1_PredictRequest Mount Wrong URL HOT 1
- Empty API References Page for v0.16.1 release for Google API {Spanner, Notebooks, Manufacturers} HOT 1
- Synthesis failed for Transcoder HOT 10
- is batch uploads supported? HOT 1
- dfareporting v4 has been released HOT 1
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 elixir-google-api.