docs: fix usage page to match latest version's default adapter specification (#1447)

This commit is contained in:
mi-wada 2022-09-06 00:11:48 +09:00 committed by GitHub
parent 4816043101
commit 7926e3aa89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 16 deletions

View File

@ -10,6 +10,28 @@ a Faraday response object. Adapters are typically implemented with common Ruby
HTTP clients, but can have custom implementations. Adapters can be configured HTTP clients, but can have custom implementations. Adapters can be configured
either globally or per Faraday Connection through the configuration block. either globally or per Faraday Connection through the configuration block.
For example, consider using `httpclient` as an adapter. Note that [faraday-httpclient](https://github.com/lostisland/faraday-httpclient) must be installed beforehand.
If you wants to configure it globally, do the following:
```ruby
require 'faraday'
require 'faraday/httpclient'
Faraday.default_adapter = :httpclient
```
If you want to configure it per Faraday Connection, do the following:
```ruby
require 'faraday'
require 'faraday/httpclient'
conn = Faraday.new do |f|
f.adapter :httpclient
end
```
{: .mt-60} {: .mt-60}
## Fantastic adapters and where to find them ## Fantastic adapters and where to find them

View File

@ -10,22 +10,7 @@ order: 1
Let's fetch the home page for the wonderful Let's fetch the home page for the wonderful
[httpbingo.org](https://httpbingo.org) service. [httpbingo.org](https://httpbingo.org) service.
First of all, you need to tell Faraday which [`adapter`](../adapters) you wish to use. You can make a simple `GET` request using `Faraday.get`:
Adapters are responsible for actually executing HTTP requests.
There are many different adapters you can choose from.
Just pick the one you like and install it, or add it to your project Gemfile.
You might want to use Faraday with the `Net::HTTP` adapter, for example.
[Learn more about Adapters](../adapters).
Remember you'll need to install the corresponding adapter gem before you'll be able to use it.
```ruby
require 'faraday'
require 'faraday/net_http'
Faraday.default_adapter = :net_http
```
Next, you can make a simple `GET` request using `Faraday.get`:
```ruby ```ruby
response = Faraday.get('http://httpbingo.org') response = Faraday.get('http://httpbingo.org')
@ -135,6 +120,13 @@ end
# => POST http://httpbingo.org/post?limit=100 # => POST http://httpbingo.org/post?limit=100
``` ```
### Adapters
Adapters are responsible for actually executing HTTP requests. The default
adapter uses Ruby's `Net::HTTP`, but there are many different adapters
available. You might want to use Faraday with the Typhoeus adapter, for example.
[Learn more about Adapters](../adapters).
### Middleware ### Middleware
Under the hood, Faraday uses a Rack-inspired middleware stack for making Under the hood, Faraday uses a Rack-inspired middleware stack for making