class Faraday::RackBuilder
end
builder.adapter :net_http # Faraday::Adapter::NetHttp
builder.request :url_encoded # Faraday::Request::UrlEncoded
Faraday::Connection.new(url: ‘sushi.com’) do |builder|
@example
middleware stack (heavily inspired by Rack).
A Builder that processes requests into responses by passing through an inner
def ==(other)
def ==(other) other.is_a?(self.class) && @handlers == other.handlers && @adapter == other.adapter end
def [](idx)
def [](idx) @handlers[idx] end
def adapter(klass = NO_ARGUMENT, *args, &block)
def adapter(klass = NO_ARGUMENT, *args, &block) er if klass == NO_ARGUMENT || klass.nil? ay::Adapter.lookup_middleware(klass) if klass.is_a?(Symbol) lf.class::Handler.new(klass, *args, &block)
def adapter_set?
def adapter_set? !@adapter.nil? end
def app
to the middleware stack.
the builder gets locked to ensure no further modifications are made
The builder is responsible for creating the app object. After this,
The "rack app" wrapped in middleware. All requests are sent here.
def app @app ||= begin lock! ensure_adapter! to_app end end
def assert_index(index)
def assert_index(index) idx = index.is_a?(Integer) ? index : @handlers.index(index) raise "No such handler: #{index.inspect}" unless idx idx end
def build
def build raise_if_locked block_given? ? yield(self) : request(:url_encoded) adapter(Faraday.default_adapter, **Faraday.default_adapter_options) unless @adapter end
def build_env(connection, request)
:password - Proxy server password
:user - Proxy server username
:uri - Proxy Server URI
:proxy - Hash of proxy options
:open_timeout - read timeout Integer in seconds
:timeout - open/read timeout Integer in seconds
:request - Hash of options for configuring the request.
:parallel_manager - sent if the connection is in parallel mode
:response_headers - Hash of HTTP headers from the server
:request_headers - hash of HTTP Headers to be sent to the server
:status - HTTP response status code
:url - URI instance for the current request.
:body - the request body that will eventually be converted to a string.
:http_method - a symbolized request HTTP method (:get, :post)
ENV Keys
def build_env(connection, request) exclusive_url = connection.build_exclusive_url( request.path, request.params, request.options.params_encoder ) Env.new(request.http_method, request.body, exclusive_url, request.options, request.headers, connection.ssl, connection.parallel_manager) end
def build_response(connection, request)
-
(Faraday::Response)
-
Parameters:
-
request
(Faraday::Request
) -- -
connection
(Faraday::Connection
) --
def build_response(connection, request) app.call(build_env(connection, request)) end
def delete(handler)
def delete(handler) raise_if_locked @handlers.delete(handler) end
def ensure_adapter!
def ensure_adapter! raise MISSING_ADAPTER_ERROR unless @adapter end
def initialize(&block)
def initialize(&block) @adapter = nil @handlers = [] build(&block) end
def initialize_dup(original)
def initialize_dup(original) super @adapter = original.adapter @handlers = original.handlers.dup end
def insert(index, *args, &block)
def insert(index, *args, &block) ed t_index(index) f.class::Handler.new(*args, &block) ert(index, handler)
def insert_after(index, *args, &block)
def insert_after(index, *args, &block) t_index(index) + 1, *args, &block)
def is_adapter?(klass) # rubocop:disable Naming/PredicateName
def is_adapter?(klass) # rubocop:disable Naming/PredicateName klass <= Faraday::Adapter end
def lock!
def lock! @handlers.freeze end
def locked?
def locked? @handlers.frozen? end
def raise_if_adapter(klass)
def raise_if_adapter(klass) return unless is_adapter?(klass) raise 'Adapter should be set using the `adapter` method, not `use`' end
def raise_if_locked
def raise_if_locked raise StackLocked, LOCK_ERR if locked? end
def request(key, *args, &block)
def request(key, *args, &block) raday::Request, key, *args, &block)
def response(key, *args, &block)
def response(key, *args, &block) raday::Response, key, *args, &block)
def swap(index, *args, &block)
def swap(index, *args, &block) ed t_index(index) ete_at(index) *args, &block)
def to_app
def to_app # last added handler is the deepest and thus closest to the inner app # adapter is always the last one @handlers.reverse.inject(@adapter.build) do |app, handler| handler.build(app) end end
def use(klass, *args, &block)
def use(klass, *args, &block) ? Symbol Faraday::Middleware, klass, *args, &block) cked apter(klass) < self.class::Handler.new(klass, *args, &block)
def use_symbol(mod, key, *args, &block)
def use_symbol(mod, key, *args, &block) p_middleware(key), *args, &block)