-
-
Save stevepiercy/4f51a05a752f1b554c7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
/**! | |
wrp | |
Quick way to grap a web_request param | |
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 | |
*/ | |
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