Module: Jets::Controller::Params
Instance Method Summary collapse
- #body_params ⇒ Object
-
#params(raw: false, path_parameters: true, body_parameters: true) ⇒ Object
Merge all the parameters together for convenience.
- #query_parameters ⇒ Object
Instance Method Details
#body_params ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jets/controller/params.rb', line 36 def body_params body = event['isBase64Encoded'] ? base64_decode(event["body"]) : event["body"] return {} if body.nil? parsed_json = parse_json(body) return parsed_json if parsed_json headers = event["headers"] || {} # API Gateway seems to use either: content-type or Content-Type headers = headers.transform_keys { |key| key.downcase } content_type = headers["content-type"] if content_type.to_s.include?("application/x-www-form-urlencoded") return ::Rack::Utils.parse_nested_query(body) elsif content_type.to_s.include?("multipart/form-data") return parse_multipart(body) end {} # fallback to empty Hash end |
#params(raw: false, path_parameters: true, body_parameters: true) ⇒ Object
Merge all the parameters together for convenience. Users still have access via events.
Precedence:
1. path parameters have highest precdence
2. query string parameters
3. body parameters
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jets/controller/params.rb', line 16 def params(raw: false, path_parameters: true, body_parameters: true) path_params = event["pathParameters"] || {} params = {} params = params.deep_merge(body_params) if body_parameters params = params.deep_merge(query_parameters) # always params = params.deep_merge(path_params) if path_parameters if raw params else params = ActionDispatch::Request::Utils.normalize_encode_params(params) # for file uploads ActionController::Parameters.new(params) end end |
#query_parameters ⇒ Object
32 33 34 |
# File 'lib/jets/controller/params.rb', line 32 def query_parameters event["queryStringParameters"] || {} end |