Lasso Soft Inc. > Home

[web_request_params]

Linkweb_request_params
AuthorKe Carlton
CategoryAction
Version9.x
LicensePublic Domain
Posted05 Aug 2015
Updated05 Aug 2015
More by this author...

Description

These methods allow you to work with web_request params in a more convenient and faster manner. 

web_request timer:  (micros_average = 209.930000)
getparam timer: (micros_average = 130.580000)

Sample Usage

getparams // map containing all get params
postparams // map containing all post params

getparam('test') // value of all get params named test joined by break
getparam('test',1) // value of first instance of get param named test
getparam('test',2) // value of second instance of get param named test
getparam('test',-count) // return the number of get param instances named test

postparam('test') // value of all post params named test joined by break
postparam('test',1) // value of first instance of post param named test
postparam('test',2) // value of second instance of post param named test
postparam('test',-count) // return the number of post param instances named test


Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define getparams => {
	var(_getparams) ? return $_getparams 
	return $_getparams := collateparams(web_request->queryparams)
}

define postparams => {
	var(_postparams) ? return $_postparams
	return $_postparams := collateparams(web_request->postparams)
}

define collateparams(params::trait_foreach) => {
	local(m = map,n,v,p) 
	#params->foreach => { 
		#p = #1
		#n = #p->first
		if(#n) => {
			#v = #m->find(#n)
			#v->isa(::array) 
			? #v->insert(#p->second)
			| #v = array(#p->second)
		}
		#m->insert(#n = #v)
	}
	return #m
}

define getparam(name::string) 	=> (getparams->find(#name) || staticarray)->join('\n') 
define postparam(name::string) 	=> (postparams->find(#name) || staticarray)->join('\n')

define getparam(name::string,i::integer) 	=> protect => {return getparams->find(#name)->get(#i)}
define postparam(name::string,i::integer) 	=> protect => {return postparams->find(#name)->get(#i)}

define getparam(name::string,-count) 	=> (getparams->find(#name) || staticarray)->size
define postparam(name::string,-count) 	=> (postparams->find(#name) || staticarray)->size

Comments

17 Oct 2013, Ke Carlton

-count added.

Thanks for suggestion.

17 Oct 2013, Jolle Carlestam

Adding a count

Great value in these additions!
A humble suggestion is to expand with a count signature:

getparam('name', -count)
-> 3

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft