Changeset 18257 in project


Ignore:
Timestamp:
05/30/10 16:35:30 (11 years ago)
Author:
Mario Domenech Goulart
Message:

Updated docs for spiffy-request-vars 0.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/spiffy-request-vars

    r18253 r18257  
    4040
    4141If 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 {{#f}}.
     42
     43
     44<procedure>(as-alist variable variables/values)</procedure>
     45
     46Returns an alist represented by the request variables/values for the given variable.  The request representation for alists is {{variable.key=value}}.  Example: {{foo.a=1}} would result in {{'((a . "1"))}} for the {{foo}} variable.
     47
     48Example:
     49
     50<enscript highlight=scheme>
     51;; considering a http://server:port/path?foo.a=0&foo.a=1 request
     52
     53(let (($ (request-vars)))
     54  ($ 'foo as-alist))   ;; => ((a . "0") (b . "1"))
     55</enscript>
     56
     57{{as-alist}} returns {{#f}} when the wanted variable is not sent in the request or it is sent not in the ''dot'' notation (e.g., {{foo=0}}).
     58
     59
     60<procedure>(as-hash-table variable variables/values)</procedure>
     61
     62The same as {{as-alist}}, but returns a hash-table object instead of an alist.
     63
     64
     65
     66<procedure>(as-vector variable variables/values)</procedure>
     67
     68Returns a vectir represented by the request variables/values for the given variable.  The request representation for vectors is {{variable.numeric-index=value}}.  Example: {{foo.0=1}} would result in {{#("1")}} for the {{foo}} variable.
     69
     70Example:
     71
     72<enscript highlight=scheme>
     73;; considering a http://server:port/path?foo.0=a&foo.1=b
     74
     75(let (($ (request-vars)))
     76  ($ 'foo as-vector))   ;; => #("a" "b")
     77</enscript>
     78
     79{{as-vector}} returns {{#f}} when the wanted variable is not sent in the request or it is sent not in the ''dot'' notation (e.g., {{foo=0}}).
     80
     81If the vector represented by the request is sparse, the missing items are unspecified values.
    4282
    4383
     
    182222  (list foo bar baz) => ("10" ("1" "2") "-8")
    183223
     224
     225;; http://host:port
     226
     227(with-request-vars ((foo as-alist) (bar as-number) (baz as-vector) (bool as-boolean))
     228  (list foo bar baz bool)) => (#f #f #f #f)
     229
     230
     231;; http://host:port/?foo.A=0&foo.B=1&bar=0&baz.0=a&baz.1=b&bool=yes
     232
     233(with-request-vars ((foo as-alist) (bar as-number) (baz as-vector) (bool as-boolean))
     234  (list foo bar baz bool)) => (((A . "0") (B . "1")) 0 #("a" "b") #t)
     235
     236
     237;; http://host:port/?foo=0&bar=a&baz=0&bool=3
     238
     239(with-request-vars ((foo as-alist) (bar as-number) (baz as-vector) (bool as-boolean))
     240  (list foo bar baz bool)) => (#f #f #f #f)
     241
     242
    184243</enscript>
    185244
     
    223282=== Version history
    224283
     284; 0.9 : added {{as-vector}}, {{as-alist}} and {{as-hash-table}} as converters.
    225285; 0.8 : bug fix/improvement: don't bother reading the request body when the content-length is zero (fixes some awful/jquery ajax issues)
    226286; 0.7 : bug fix.  Interpret request body before query string.
Note: See TracChangeset for help on using the changeset viewer.