Module: Roda::RodaPlugins::JsonParser::RequestMethods
- Defined in:
- lib/roda/plugins/json_parser.rb
Instance Method Summary collapse
-
#POST ⇒ Object
If the Content-Type header in the request includes “json”, parse the request body as JSON.
Instance Method Details
#POST ⇒ Object
If the Content-Type header in the request includes “json”, parse the request body as JSON. Ignore an empty request body.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/roda/plugins/json_parser.rb', line 42 def POST env = @env if post_params = (env[JSON_PARAMS_KEY] || env[FORM_HASH_KEY]) post_params elsif (input = env[INPUT_KEY]) && content_type =~ /json/ str = input.read input.rewind return super if str.empty? begin json_params = env[JSON_PARAMS_KEY] = parse_json(str) rescue roda_class.opts[:json_parser_error_handler].call(self) end env[FORM_INPUT_KEY] = input json_params else super end end |