Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Matt
    @iMacTia
    But I can check the code later on and confirm/deny
    Agree it would be useful at least
    FLk823
    @ZhaoZijie
    @iMacTia thankyou
    Matt
    @iMacTia
    @ZhaoZijie So unfortunately I checked the code and I can confirm there's no such helper in Faraday at the moment. I guess that's mostly because cookies are not a good practice for server-server communication. That said, I did find a gem called faraday-cookie_jar that implemented cookies forwarding between faraday requests as a middleware.
    if that's not exactly what you need, and you simply need to parse cookies, then that gem uses http-cookie to do that, you can see how that works in the middleware on_complete function: https://github.com/miyagawa/faraday-cookie_jar/blob/master/lib/faraday/cookie_jar.rb
    I hope at least this helps!
    Daniel Martinez Sarta
    @danielmartinezsarta
    Hi all! I have a problem using Faraday with docker, I don't know if docker it's the problem really. I'm calling an API with postman and with the same parameters and body using Faraday i get "execution expired" exception.
    Matt
    @iMacTia
    Hi @danielmartinezsarta , Docker can be quite fussy when it comes to networking. Also, networking changes significantly inside and outside of containers.
    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?
    Is it from inside a container or outside?
    Bobby McDonald
    @BobbyMcWho
    Does Faraday provide a resolved IP on the response object by any chance? I can't find anything in source code, so I'm assuming no, but wanted to confirm
    Bobby McDonald
    @BobbyMcWho
    Looks like Typhoeus (the adapter I'm using ) provides a #primary_ip method, need to see if I can access that without monkey-patching
    Bobby McDonald
    @BobbyMcWho
    Submitted a feature request: lostisland/faraday#1186
    Matt
    @iMacTia
    👍👍
    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