Handling parameters
TODO
There are 4 ways parameters are send to the server:
- within the URL itself
- as URL parameter
- as HTML Form values
- via cookies
Reading parameters is only one call:
Context.Request.Params['ParamName']
Parameters are read in the following order:
- URL Mapped parameters
- Query String parameters
- FORM parameters(eg. HTML Form Submit)
- Cookie fields
URL mapped parameters
GET /blog/posts/danieleteti/2013/11
[MVCPath('/posts/($user)/($year)/($month)')]
[MVCHTTPMethod([httpGET])]
procedure GetArticles(CTX: TWebContext);
. . .
procedure GetArticles(CTX: TWebContext);
var
year, month: Integer;
user: string;
begin
user := CTX.Request.Params['user'];
year := CTX.Request.Params['year'].ToInteger;
month := CTX.Request.ParamsAsInteger['month'];
end
QueryString mapped parameters
GET /blog/posts/danieleteti?year=2013&month=11
[MVCPath('/posts/($user)')]
[MVCHTTPMethod([httpGET])]
procedureGetArticles(CTX: TWebContext);
. . .
procedure GetArticles(CTX: TWebContext);
var
year, month: Integer;
user: string;
begin
user := CTX.Request.Params['user'];
year := CTX.Request.Params['year'].ToInteger;
month := CTX.Request.ParamsAsInteger['month'];
end