Class: Faraday::Request::Json
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::Json
- Defined in:
- lib/faraday/request/json.rb
Overview
Request middleware that encodes the body as JSON.
Processes only requests with matching Content-type or those without a type. If a request doesn’t have a type but has a body, it sets the Content-type to JSON MIME-type.
Doesn’t try to encode bodies that already are in string form.
Constant Summary collapse
- MIME_TYPE =
'application/json'
- MIME_TYPE_REGEX =
%r{^application/(vnd\..+\+)?json$}
Constants inherited from Middleware
Middleware::DEFAULT_OPTIONS, Middleware::LOCK
Instance Attribute Summary
Attributes inherited from Middleware
Instance Method Summary collapse
Methods inherited from Middleware
#call, #close, default_options, default_options=, #initialize
Methods included from MiddlewareRegistry
#lookup_middleware, #register_middleware, #registered_middleware, #unregister_middleware
Constructor Details
This class inherits a constructor from Faraday::Middleware
Instance Method Details
#on_request(env) ⇒ Object
18 19 20 21 22 |
# File 'lib/faraday/request/json.rb', line 18 def on_request(env) match_content_type(env) do |data| env[:body] = encode(data) end end |