Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active May 2, 2017 06:15
Show Gist options
  • Save jolle-c/d72c8af689cb7e79ccc1 to your computer and use it in GitHub Desktop.
Save jolle-c/d72c8af689cb7e79ccc1 to your computer and use it in GitHub Desktop.
Quick way to grap a web_request param. For Lasso 9
[
/**!
wrp
Quick way to grap a web_request param
2017-05-02 JC Added examples
2014-10-08 JC Added to Gist
2014-10-08 JC Added separate methods for queryparams and postparams
2014-08-24 JC Rewrite of the wrp method once again. This time with code suggested by Brad Lindsay in a lassotalk thread. Introduces the param -all
2014-08-22 JC Complete rewrite to produce leaner and more reliable code. Arrays are now returned as staticarrays
2013-12-08 JC adjusted to only initiate once
2013-12-07 JC First version
EXAMPLES
local(
checkboxinput = wrp('checkboxinput', -all),
myinput = wrp('myinput')
)
#checkboxinput -> type // staticarray
#myinput -> type // string or void depending on if it has content or not
// this will only find GET parameters
local(
myqueryparam = wrpq('myqueryparam')
)
// this will only find POST parameters
local(
mypostparam = wrpp('mypostparam')
)
*/
define wrps => var(__wrp) -> isa(::staticarray) ?
$__wrp |
$__wrp := (with p in web_request -> params
let name = #p -> first -> asstring
let value = #p -> second -> asstring
select pair(#name = #value)) -> asstaticarray
define wrp(name::string = string, -all::boolean = false) => {
local(wrp) = wrps -> find(#name)
if(#all) => {
return (with param in #wrp select #param -> second) -> asstaticarray
}
#wrp -> isempty ? return void
return #wrp -> get(1) -> second
}
define wrpqs => var(__wrpq) -> isa(::staticarray) ?
$__wrpq |
$__wrpq := (with p in web_request -> queryparams
let name = #p -> first -> asstring
let value = #p -> second -> asstring
select pair(#name = #value)) -> asstaticarray
define wrpq(name::string = string, -all::boolean = false) => {
local(wrp) = wrpqs -> find(#name)
if(#all) => {
return (with param in #wrp select #param -> second) -> asstaticarray
}
#wrp -> isempty ? return void
return #wrp -> get(1) -> second
}
define wrpps => var(__wrpp) -> isa(::staticarray) ?
$__wrpp |
$__wrpp := (with p in web_request -> postparams
let name = #p -> first -> asstring
let value = #p -> second -> asstring
select pair(#name = #value)) -> asstaticarray
define wrpp(name::string = string, -all::boolean = false) => {
local(wrp) = wrpps -> find(#name)
if(#all) => {
return (with param in #wrp select #param -> second) -> asstaticarray
}
#wrp -> isempty ? return void
return #wrp -> get(1) -> second
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment