(index ("request-vars" 0) ("as-string" 1712) ("as-symbol" 1916) ("as-number" 2094) ("as-boolean" 2272) ("as-list" 2628) ("as-alist" 2959) ("as-hash-table" 3661) ("as-vector" 3840) ("nonempty" 4632) ("true-boolean-values" 5337) ("compound-variable-separator" 5688) ("with-request-vars" 6339) ("with-request-vars*" 7044))
(def (sig (procedure "(request-vars #!key (source 'request-method) max-content-length)" (id request-vars))) (p (tt "request-vars") " returns a procedure which can be used to access variables from the HTTP request.  The returned procedure takes the name of the variable (either a symbol or a string) as argument. You can (optionally) also pass a converter procedure to be used as a type converter for the variable value (see Converter procedures) or a default value.") (p (tt "request-vars") " accepts some keyword arguments:") (dl (dt (tt "source")) (dd (tt "'query-string") " tells " (tt "request-vars") " to parse the query string only (for GET variables). " (tt "'request-body") " tells " (tt "request-vars") " to parse the request body only (e.g., for POST variables). " (tt "'both") " tells " (tt "request-vars") " to parse both the request body and the query string. " (tt "'request-method") " tells " (tt "request-vars") " to parse only the source that matches the request method (e.g., for a " (tt "GET") " request, only the query string will be read; for a " (tt "POST") " request, only the request body will be read). The default value for " (tt "source") " is " (tt "'request-method") " (since version 0.18 -- previous versions used " (tt "'both") "). Notice that when " (tt "'both") " is used, variables from the request body have precedence over the ones from the query string.  " (b "Warning") ": using " (tt "'both") " as source for " (tt "request-vars") " may be a security issue (see the release notes for version 0.18 for more details).") (dt (tt "max-content-length")) (dd "the maximum content length (in characters) to be read from the request body.  Default is " (tt "#f") " (no limit).")))
(def (sig (procedure "(as-string variable variables/values)" (id as-string))) (p "If the given variable is set, return its value as a string (that's the default behavior if no converter is specified)."))
(def (sig (procedure "(as-symbol variable variables/values)" (id as-symbol))) (p "If the given variable is set, convert its value to a symbol using " (tt "string->symbol") "."))
(def (sig (procedure "(as-number variable variables/values)" (id as-number))) (p "If the given variable is set, convert its value to a number using " (tt "string->number") "."))
(def (sig (procedure "(as-boolean variable variables/values)" (id as-boolean))) (p "If the variable is set and its value is one of the values yield by the " (tt "true-boolean-values") " parameter, return " (tt "#t") ", otherwise return " (tt "#f") ". It also returns " (tt "#t") " if the variable is passed in the request but is not bound to any value."))
(def (sig (procedure "(as-list variable variables/values)" (id as-list))) (p "If the variable is set once, returns a list with a single element (the value for the given variable).  If the variable is set multiple times, return a list with the multiple values for the variable.  If the variable is not set, return " (tt "#f") "."))
(def (sig (procedure "(as-alist variable variables/values)" (id as-alist))) (p "Returns an alist represented by the request variables/values for the given variable.  The request representation for alists is " (tt "variable.key=value") ".  Example: " (tt "foo.a=1") " would result in " (tt "'((a . \"1\"))") " for the " (tt "foo") " variable.") (p "Example:") (highlight scheme ";; considering a http://server:port/path?foo.a=0&foo.b=1 request\n\n(let (($ (request-vars)))\n  ($ 'foo as-alist))   ;; => ((a . \"0\") (b . \"1\"))") (p (tt "as-alist") " returns " (tt "#f") " when the wanted variable is not sent in the request or it is sent not in the " (i "dot") " notation (e.g., " (tt "foo=0") ")."))
(def (sig (procedure "(as-hash-table variable variables/values)" (id as-hash-table))) (p "The same as " (tt "as-alist") ", but returns a hash-table object instead of an alist."))
(def (sig (procedure "(as-vector variable variables/values)" (id as-vector))) (p "Returns a vectir represented by the request variables/values for the given variable.  The request representation for vectors is " (tt "variable.numeric-index=value") ".  Example: " (tt "foo.0=1") " would result in " (tt "#(\"1\")") " for the " (tt "foo") " variable.") (p "Example:") (highlight scheme ";; considering a http://server:port/path?foo.0=a&foo.1=b\n\n(let (($ (request-vars)))\n  ($ 'foo as-vector))   ;; => #(\"a\" \"b\")") (p (tt "as-vector") " returns " (tt "#f") " when the wanted variable is not sent in the request or it is sent not in the " (i "dot") " notation (e.g., " (tt "foo=0") ").") (p "If the vector represented by the request is sparse, the missing items are unspecified values."))
(def (sig (procedure "(nonempty converter)" (id nonempty))) (p "A combinator to be used with converters.  Returns the converter value if the variable is set and its value is not null.  Returns " (tt "#f") " if its value is null.") (p "It can be useful for handling values from form-submited data, when all form fields are submited, but some are null.  If you are only interested in values that are not null, you can just check if the return value of " (tt "nonempty") " is not " (tt "#f") " (otherwise you'd have to check if the variable was actually in the request and if its value is not null).") (p "Example:") (highlight scheme "(let ((var (or ($ 'var (nonempty as-string)) \"not set\")))\n   var)"))
(def (sig (parameter "(true-boolean-values [list])" (id true-boolean-values))) (p "A list of values (strings) to be considered as " (tt "#t") " for request variables when " (tt "as-boolean") " is used as converter.") (p "The default value is " (tt "'(\"y\" \"yes\" \"1\" \"on\" \"true\")") ".  The values are compared using " (tt "string-ci=?") "."))
(def (sig (parameter "(compound-variable-separator [string])" (id compound-variable-separator))) (p "A string representing the separator for request variable names bound to compound data types (vectors, alists, hash-tables).  The default value is " (tt "\".\"") ".") (p "For example, if " (tt "(compound-variable-separator)") " yields " (tt "\".\"") " and the query string is " (tt "?foo.A=0&foo.B=1") ", if you bind it as an alist, you'll get " (tt "((A . 0) (B . 1))") ".  If you want the same behavior, but for query string with variables like " (tt "?foo_A=0&foo_B=1") ", you can set " (tt "compound-variable-separator") " to " (tt "\"_\"") "."))
(def (sig (syntax "(with-request-vars [getter] (var1 var2 ... varN) expr1 expr2 ... exprN)" (id with-request-vars))) (p "Bind the given identifiers to the corresponding query string and request body variable values and evaluate the expressions.  The optional " (tt "getter") " argument (the return value of " (tt "request-vars") ") may be used in situations when you already have the getter and don't want to reparse the query string and request body.  With " (tt "with-request-vars*") ", the given getter will be used and no reparsing will be performed.  When the syntax is ambiguous (e.g., " (tt "(with-request-vars (request-vars) (var1 var2) (body))") ", " (tt "with-request-vars*") " can be used)."))
(def (sig (syntax "(with-request-vars* getter (var1 var2 ... varN) expr1 expr2 ... exprN)" (id with-request-vars*))) (p "The same as " (tt "with-request-vars") ", but the getter is mandatory."))
