Class | Faraday::Connection |
In: |
lib/faraday/connection.rb
|
Parent: | Object |
Public: Connection objects manage the default properties and the middleware stack for fulfilling an HTTP request.
Examples
conn = Faraday::Connection.new 'http://sushi.com' # GET http://sushi.com/nigiri conn.get 'nigiri' # => #<Faraday::Response>
METHODS | = | Set.new [:get, :post, :put, :delete, :head, :patch, :options] | A Set of allowed HTTP verbs. |
builder | [R] | Public: Returns the Faraday::Builder for this Connection. |
default_parallel_manager | [W] | Public: Sets the default parallel manager for this connection. |
headers | [R] | Public: Returns a Hash of unencoded HTTP header key/value pairs. |
options | [R] | Public: Returns a Hash of the request options. |
parallel_manager | [R] | Public: Returns the parallel manager for this Connection. |
params | [R] | Public: Returns a Hash of URI query unencoded key/value pairs. |
ssl | [R] | Public: Returns a Hash of the SSL options. |
url_prefix | [R] | Public: Returns a URI with the prefix used for all requests from this Connection. This includes a default host name, scheme, port, and path. |
Public: Initializes a new Faraday::Connection.
url - URI or String base URL to use as a prefix for all
requests (optional).
options - Hash or Faraday::ConnectionOptions.
:url - URI or String base URL (default: "http:/"). :params - Hash of URI query unencoded key/value pairs. :headers - Hash of unencoded HTTP header key/value pairs. :request - Hash of request options. :ssl - Hash of SSL options. :proxy - URI, String or Hash of HTTP proxy options (default: "http_proxy" environment variable). :uri - URI or String :user - String (optional) :password - String (optional)
Public: Sets up a custom Authorization header.
type - The String authorization type. token - The String or Hash token. A String value is taken literally, and
a Hash is encoded into comma separated key/value pairs.
Examples
conn.authorization :Bearer, 'mF_9.B5f-4.1JqM' conn.headers['Authorization'] # => "Bearer mF_9.B5f-4.1JqM" conn.authorization :Token, :token => 'abcdef', :foo => 'bar' conn.headers['Authorization'] # => "Token token=\"abcdef\", foo=\"bar\""
Returns nothing.
Public: Sets up the Authorization header with these credentials, encoded with base64.
login - The authentication login. pass - The authentication password.
Examples
conn.basic_auth 'Aladdin', 'open sesame' conn.headers['Authorization'] # => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
Returns nothing.
Internal: Build an absolute URL based on url_prefix.
url - A String or URI-like object params - A Faraday::Utils::ParamsHash to replace the query values
of the resulting url (default: nil).
Returns the resulting URI instance.
Public: Takes a relative url for a request and combines it with the defaults set on the connection instance.
conn = Faraday::Connection.new { ... } conn.url_prefix = "https://sushi.com/api?token=abc" conn.scheme # => https conn.path_prefix # => "/api" conn.build_url("nigiri?page=2") # => https://sushi.com/api/nigiri?token=abc&page=2 conn.build_url("nigiri", :page => 2) # => https://sushi.com/api/nigiri?token=abc&page=2
Internal: Traverse the middleware stack in search of a parallel-capable adapter.
Yields in case of not found.
Returns a parallel manager or nil if not found.
Public: Sets up the parallel manager to make a set of requests.
manager - The parallel manager that this Connection‘s Adapter uses.
Yields a block to execute multiple requests. Returns nothing.
Public: Determine if this Faraday::Connection can make parallel requests.
Returns true or false.
Public: Sets the path prefix and ensures that it always has a leading slash.
value - A String.
Returns the new String path prefix.
Builds and runs the Faraday::Request.
method - The Symbol HTTP method. url - The String or URI to access. body - The String body headers - Hash of unencoded HTTP header key/value pairs.
Returns a Faraday::Response.
Public: Sets up the Authorization header with the given token.
token - The String token. options - Optional Hash of extra token options.
Examples
conn.token_auth 'abcdef', :foo => 'bar' conn.headers['Authorization'] # => "Token token=\"abcdef\", foo=\"bar\""
Returns nothing.
Public: Parses the giving url with URI and stores the individual components in this connection. These components serve as defaults for requests made by this connection.
url - A String or URI.
Examples
conn = Faraday::Connection.new { ... } conn.url_prefix = "https://sushi.com/api" conn.scheme # => https conn.path_prefix # => "/api" conn.get("nigiri?page=2") # accesses https://sushi.com/api/nigiri
Returns the parsed URI from teh given input..