class Saddle::Middleware::Request::JsonEncoded
Request
middleware that encodes the body as JSON.
Make sure you set request = :json for it to be activated.
Constants
- CONTENT_TYPE
- MIME_TYPE
Public Instance Methods
call(env)
click to toggle source
# File lib/saddle/middleware/request/encode_json.rb, line 16 def call(env) if env[:saddle][:request_style] == :json # Make sure we're working with a valid body that's not a String if env[:body] and !env[:body].respond_to?(:to_str) env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE env[:body] = ::JSON.dump(env[:body]) end end @app.call env end