Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Daniel Martinez Sarta
    @danielmartinezsarta
    You mentioned Postman, which I'd assume is the application running on your computer, but when you say that you get "execution expired" with Faraday, where is this Ruby code running?
    Hi Matt, thanks for your response, it appears that docker network was the problem, I did a docker system prune and also I changed the way that I was creating the http client to block format and now It is working flawlessly
    Matt
    @iMacTia
    That’s great to hear @danielmartinezsarta 🙌
    jmarsh24
    @jmarsh24
    hellooooo
    Matt
    @iMacTia
    👋👋
    Danilo Domínguez Pérez
    @danilo04
    Hi all, I am trying to test faraday's retries but I cannot find any documentation about it. I tried the Faraday stubs but didn't work.
    Is there any way to test the retries in Faraday, like making several stubs for the same endpoint, so they can be returned on each retry
    Matt
    @iMacTia
    Hi @danilo04, it really depends on the trigger for the retry (timeout or response status code), but I usually use the Faraday Test Adapter or a solution like Webmock. You can also check how we test it here
    Danilo Domínguez Pérez
    @danilo04
    HI @iMacTia, I think I can control the tests with the callback. Works for me. Thanks!!
    Abdallah Nehme
    @abdallahnh
    Hi all,
    I'm facing this error Faraday::ForbiddenError: [!] the server responded with status 403 since 2 days ago, i opened an issue on github/fastlane, firebase support, stackoverflow and till now i got no answers
    https://stackoverflow.com/questions/66117989/firebase-ios-distribution-faraday-server-error-403
    fastlane/fastlane#18170
    can anyone help please, thanks
    I'm using CirclCI, Fastlane, and Firebase App Distribution for our CD
    Matt
    @iMacTia
    Hi @abdallahnh, as the error says, it seems like the server is returning a 403 status response. 403 is standard for an unauthorised operation being carried out. Unfortunately, Faraday is simply the messenger in this case, and I don’t know why you’re getting a 403 response back or why it was working until the other day and now stopped. Those are questions for the CircleCI, Fastlane and Firebase teams, which I’m sure will be able to help.
    In the meantime you could think of possibilities on why you’d receive a 403. Looking at the logs I can see you’re authenticating with a FIREBASE_TOKEN, and the authentication is successful. So the token looks OK, but maybe the account that token is bound to doesn’t have permissions to upload the IPA? That would explain a 403 error. Did you enable 2FA/MFA recently on that account maybe? Or did you, or your account administrator, made any change to permissions?
    I’m sorry I can’t help you more than this, just trying to point you in the right direction while you wait for help from the other teams
    Abdallah Nehme
    @abdallahnh
    Thanks alot @iMacTia ya you are right, it is from the FIREBASE_TOKEN and it seems the linked account was removed from our Firebased and that's caused this issue, i just created a new token and updated the CircleCI Environment key
    Matt
    @iMacTia
    That is great 🎉! Glad I could help 👍
    jmkozko
    @jmkozko
    forgive me for my newbish question but is it possible to have every Faraday call use some preset header values so that it doesn't have to be passed as an argument every single call? i have some values i need to pass in the headers for authentication and would like to set once and not worry about it. or is this a bad idea?
    Matt
    @iMacTia
    Hey @jmkozko, that’s far from a new bush question! It really depends on how you use Faraday. The correct way to do this would be to create one connection object with the server (API) base url and then make requests against the same connection object by providing the path and the parameters.
    If you do this. Then you can provide headers to the connection as an option when you initialise it, and those will be passed to all requests performed with that connection
    jmkozko
    @jmkozko
    oh awesome, that should do the trick. i'll give it a try. thanks
    Here you can see an example of creating a connection object with the headers option
    Márcio Soares
    @biodevs
    Hello, I would like some help on a faraday.get connection that always returns a TrueClass and not a Faraday::Response in rails. I will be grateful for the attention.
    Matt
    @iMacTia
    Hey @biodevs, happy to help. Probably the issue is with the way the connection is setup. Could you please open an issue in the Faraday repo and share as much details as possible?
    satya konidala
    @satyakonidala

    Hi, How do I use faraday to run requests parallelly when there is dependency among requests? For example, consider the below scenario:

    Main Dep1 Dep2
    1 -> 1.1 -> 1.2
    2
    3 -> 3.1 -> 3.2
    4 -> 4.1

    You can read the above as the app wanting to make a total of 9 requests with requests under Dep1 and Dep2 depending on the response from the main request. So, request 1.2 depends on request 1.1 which in turn depends on main request 1.

    Rod Jenkins
    @scriptmonkey
    Hello Ll
    Rod Jenkins
    @scriptmonkey
    Hello all, I’m new around here. I have a newbie question. I need to be able to use Faraday to send a POST, “application/json”, but with a null body.
    Rod Jenkins
    @scriptmonkey
    I can provide the curl command I am trying to replicate if the is helpful.
    Matt
    @iMacTia
    Hi @satyakonidala :wave:! Faraday::Response offers a method called on_complete, you can use that to chain dependent requests. Sorry about that lack of documentation around this but parallel requests is not a strength for any of the remaining maintainers, so we struggle a bit to provide support on this topic. We hope to revamp and improve this in the next major version though :thumbsup:
    Please do let me know if the above works!
    Hi @scriptmonkey :wave:! The curl example would definitely help, because I'm not sure the JSON standard allows for a "null" body, just an empty one I believe. But if you're able to make it work with curl we most probably can make it work on Faraday !
    Rod Jenkins
    @scriptmonkey
    @iMacTia I do feel nice that there was not a silly simple answer. Here is the curl command:
    curl -X POST https://api.dropboxapi.com/2/users/get_current_account \ --header 'Authorization: Bearer mysupersecrettoken' \ --header 'Content-Type: application/json' \ --data 'null'
    Matt
    @iMacTia

    @scriptmonkey that looks to me like a simple string body with the word "null" is that it?
    In that case, I believe you should be able to set that as your request body and manually set the Content-Typeheader

    Faraday.post("https://api.dropboxapi.com/2/users/get_current_account", 'null', "Content-Type" => "application/json", "Authorization" => "Bearer mysupersecrettoken")

    Here is another example taking full advantage of Faraday tools and middleware, including those provided by the faraday_middleware gem:

    require 'faraday'
    require 'faraday_middleware'
    
    base_url = 'https://api.dropboxapi.com/2'
    
    conn = Faraday.new(base_url) do |f|
      f.request :authorization, :Bearer, 'mysupersecrettoken'
      f.request :json
    end
    
    conn.post('users/get_current_account', 'null')

    Please do let me know if this works!

    P.S. the second snippet allows you to reuse the same connection (conn) for all subsequent calls to the same API and it will automatically make the body as JSON (even if you provide a Ruby structure like a hash or array) and set your bearer token on all requests
    satya konidala
    @satyakonidala
    @iMacTia thanks for pointing out the on_complete function. Will check that out.
    satya konidala
    @satyakonidala
    I see that on_complete is used only with middleware but not with normal request-response. I am looking for implementations how typhoeus has on_complete (https://github.com/typhoeus/typhoeus#making-parallel-requests). Do you mind pointing me out to any available examples?
    Matt
    @iMacTia
    @satyakonidala yes you can also use that in your middleware if you want it to support async requests, but you can call on_complete on any Faraday::Response object and pass a block. That block will be called as soon as the request returns and the response is saved (or immediately, if that happened already). For example, try the following (extending typhous example here, not sure which adapter you're using):
    conn.in_parallel do
      response1 = conn.get('/first').on_complete { |response| puts response.body } 
      response2 = conn.get('/second').on_complete { |response| puts response.body }
      puts response1.body || 'nil'
      puts response2.body || 'nil'
    end
    I'd expect nil to be printed twice (last 2 lines) first, and then you should see the actual bodies being printed after the requests have been completed
    In your case, the on_complete blocks will trigger the next requests based on their dependencies
    Matt
    @iMacTia
    @satyakonidala full example (again, using typhoeus):
    require 'faraday'
    
    base_url = 'https://httpbin.org'
    
    conn = Faraday.new(url: base_url) do |builder|
      builder.request  :url_encoded
      # builder.response :logger
      builder.adapter  :typhoeus
    end
    
    conn.in_parallel do
      response1 = conn.get('/anything', {test: 'test1'}).on_complete { |response| puts response.body }
      response2 = conn.get('/anything', {test: 'test2'}).on_complete { |response| puts response.body }
      puts response1.body || 'nil'
      puts response2.body || 'nil'
    end
    satya konidala
    @satyakonidala
    @iMacTia Thank you so much! This should definitely help!
    David Friedland
    @nohat
    @iMacTia (@satyakonidala's manager here) we're looking at being able to enqueue more requests to the parallel manager inside the response block based on the contents of the response
    this doesn't appear to be possible with the current implementation of in_parallel, but we think it should be if the yield at https://github.com/lostisland/faraday/blob/main/lib/faraday/connection.rb#L379 passed in the parallel manager to the block
    is this a change that would likely get accepted if we submit a PR?
    Rod Jenkins
    @scriptmonkey
    @iMacTia Thank you for the response yesterday. I was making it too complicated trying to pass null as a value and not a string. What you proposed, worked just fine. Once I get the script working as I need, I will start digging in to the middleware portion. Thanks again.
    Matt
    @iMacTia

    @scriptmonkey that’s great to hear! Thanks for the feedback!

    @nohat ah I see your point, that way you can then reuse the parallel manager to enqueue the subsequent requests. Yeah that makes sense, I’ll happily review a PR that adds add. I’d just ask you to spend a little time improving the documentation around parallel requests with this new feature and with anything that you wished was there when you started working with them, you would be of great service to the Faraday community ❤️

    Akshat Karnwal
    @3minus1:matrix.org
    [m]
    Hi Guys. Does Faraday not work with Rails 6?
    I'm facing this error NameError (uninitialized constant Faraday)
    Rails version: 6.1.3.2 (using Zeitwork autoloading)
    Ruby version: 2.7.3
    Faraday version: 1.4.2
    1.2 version works fine
    Matt
    @iMacTia
    Hi! Faraday have no dependency with Rails or vice-versa, so you can use it in any Rails project. The problem with your error looks simply related to loading, possibly due to the new autoloader.
    Ensure that faraday is included in your Gemfile or as a dependency of a gem in it (you can check the Gemfile.lock), and that there’s no “require: false” option on it
    Akshat Karnwal
    @3minus1:matrix.org
    [m]
    Hey Matt. It does look like it's a problem with the new autoloader. I've double checked and Faraday is included in my Gemfile and is also present in my Gemfile.lock
    Again, version 1.2.0 works just fine. Any version above it seems to be facing this issue.
    Matt
    @iMacTia
    That’s really interesting, do you have a more detailed stacktrace by any chance? Trying to see if this is a direct usage or a dependency one
    Samuel Williams
    @ioquatix
    How do you create a Faraday instance with a proxy option?
            connection = Faraday.new(url: url, proxy: ENV['PROXY_URL']) do |faraday|
                faraday.response :logger
                faraday.adapter :async_http, **adapter_options
            end