You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/middleware/index.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,49 @@ conn = Faraday.new do |f|
114
114
end
115
115
```
116
116
117
+
### DEFAULT_OPTIONS
118
+
119
+
`DEFAULT_OPTIONS` improve the flexibility and customizability of new and existing middleware. Class-level `DEFAULT_OPTIONS` and the ability to set these defaults at the application level compliment existing functionality in which options can be passed into middleware on a per-instance basis.
120
+
121
+
#### Using DEFAULT_OPTIONS
122
+
123
+
Using `RaiseError` as an example, you can see that `DEFAULT_OPTIONS` have been defined at the top of the class:
124
+
125
+
```ruby
126
+
DEFAULT_OPTIONS= { include_request:true }.freeze
127
+
```
128
+
129
+
These options will be set at the class level upon instantiation and referenced as needed within the class. From our same example:
130
+
131
+
```ruby
132
+
defresponse_values(env)
133
+
...
134
+
return response unless options[:include_request]
135
+
...
136
+
```
137
+
138
+
If the default value provides the desired functionality, no further consideration is needed.
139
+
140
+
#### Setting Alternative Options per Application
141
+
142
+
In the case where it is desirable to change the default option for all instances within an application, it can be done by configuring the options in a `/config/initializers` file. For example:
After app initialization, all instances of the middleware will have the newly configured option(s). They can still be overriden on a per-instance bases (if handled in the middleware), like this:
151
+
152
+
```ruby
153
+
Faraday.newdo |f|
154
+
...
155
+
f.response :raise_error, include_request:true
156
+
...
157
+
end
158
+
```
159
+
117
160
### Available Middleware
118
161
119
162
The following pages provide detailed configuration for the middleware that ships with Faraday:
0 commit comments