Given a JSON string containing rules to validate the HTTP request, this will provide the logic to inspect and validate HTTP request and build an informative message for results. A few things to note: All rules per TYPE will be treated as 'AND'. For example, all key/value pairs in 'parameters' must exist. All rules between TYPEs will be treated as 'OR'. For example, all key/value pair rules must be TRUE in 'parameters' OR all key/value rules must be true for 'headers'.
{ "parameters": [ { "key": "ticker", "desc": "A value must be provided with the 'ticker' parameter, and it must contain the letter 'g'. Providing 'GOOG' is valid, but 'FB' will flag an error.", "value_rule_arg": "g", "value_rule_type": "string_required" }, { "key": "date", "desc": "Optional date value, but if provided, must satisfy mm/DD/yyyy format.", "value_rule_arg": "^(((0[1-9]|[12]\\d|3[01])\\/(0[13578]|1[02])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)\\/(0[13456789]|1[012])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|1\\d|2[0-8])\\/02\\/((19|[2-9]\\d)\\d{2}))|(29\\/02\\/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$", "value_rule_type": "regex_optional" } ], "headers": [ { "key": "page_id", "desc": "A page_id value MUST be provided, any non-empty string value.", "value_rule_arg": "", "value_rule_type": "string_required" } ], "body": [ { "desc": "The text 'username' is required to be present in the POST body.", "value_rule_arg": "username", "value_rule_type": "string_required" } ], "url": [ { "desc": "The value '123' is required to be present in the RESTful URL.", "value_rule_arg": "\\b123\\b", "value_rule_type": "regex_required" } ] }
@author chadlafontaine