JIMSMITH 0 Posted September 22 I created a webmodule and assigned an action pathinfo of /getname*. The question is how do I create parameters for values say parameters ssn and dob would this become /getname/($ssn)/($dob)? Would really appreciate clarity. Share this post Link to post
corneliusdavid 213 Posted September 22 2 hours ago, JIMSMITH said: assigned an action pathinfo of /getname* The pathname should not contain the asterisk, just /getname 2 hours ago, JIMSMITH said: how do I create parameters for values say parameters ssn and dob would this become /getname/($ssn)/($dob)? You don't have to "create" the parameters, by simply accessing the URL with something like /getname?ssn=123456789&dob=19990531, the TWebActionItem parses out the URI and creates the parameters for you. Then, you just access them in your event handler like this: procedure TMyWebApp.ActionHandler(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); var SSN: string; DOB: string; begin if Request.QueryFields.Count >= 2 then begin SSN := Request.QueryFields.Values['ssn']; DOB := Request.QueryFields.Values['dob']; ... The "?" starts the beginning of the list of parameters; the "&" separates the parameters. On a side note, you should never pass private info this way (using the GET method on the URL); instead you should put them in a POST BODY. But that's a different topic. Share this post Link to post
JIMSMITH 0 Posted September 22 9 hours ago, corneliusdavid said: The pathname should not contain the asterisk, just /getname You don't have to "create" the parameters, by simply accessing the URL with something like /getname?ssn=123456789&dob=19990531, the TWebActionItem parses out the URI and creates the parameters for you. Then, you just access them in your event handler like this: procedure TMyWebApp.ActionHandler(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); var SSN: string; DOB: string; begin if Request.QueryFields.Count >= 2 then begin SSN := Request.QueryFields.Values['ssn']; DOB := Request.QueryFields.Values['dob']; ... The "?" starts the beginning of the list of parameters; the "&" separates the parameters. On a side note, you should never pass private info this way (using the GET method on the URL); instead you should put them in a POST BODY. But that's a different topic. Thanks for responding to my post. This actually worked by removing the additional characters / symbols. Do you know why there are many examples the use other options in the pathinfo property? Examples are: /getname/* {seen in some youtube videos} /getname/data/:id {thoughts are that id would be a parameter} Now I am curious. Share this post Link to post
corneliusdavid 213 Posted September 22 43 minutes ago, JIMSMITH said: Do you know why there are many examples the use other options in the pathinfo property? Examples are: /getname/* {seen in some youtube videos} /getname/data/:id {thoughts are that id would be a parameter} I haven't used either of these in a WebBroker app but I think the asterisk will match any URI; for example, both /getname/list and /getname/edit. I don't remember seeing ":id" on the end of PathInfo in any examples; not sure what that's for. Share this post Link to post
hsvandrew 23 Posted September 23 Hi Jim, To handle parameters built into the URL rather than as query parameters you'll need to do the following: Assign a partial path to the 'pathInfo' of your WebModule Action i.e. /getname/* Then, in your ActionHandler you'll want to access the path part of the URL, break it into an array split by / and then execute based on the parts that matter var paths: TArray<string> = Request.PathInfo.split(['/']); //Check array length etc if sameText(paths[2],'add') then //Do add function else if sameText(paths[2],'delete') then //Do add function object.delete( paths[3] ); Hope that makes sense. I haven't tested this exact code so there might be slight syntax issues. Share this post Link to post
corneliusdavid 213 Posted September 23 59 minutes ago, hsvandrew said: To handle parameters built into the URL rather than as query parameters you'll need to do the following: Assign a partial path to the 'pathInfo' of your WebModule Action i.e. /getname/* Then, in your ActionHandler you'll want to access the path part of the URL, break it into an array split by / and then execute based on the parts that matter What would be the benefit to doing this extra work rather than letting WebBroker parse it for you into QueryFields? Share this post Link to post
JIMSMITH 0 Posted September 23 2 hours ago, corneliusdavid said: What would be the benefit to doing this extra work rather than letting WebBroker parse it for you into QueryFields? I'm just glad to know that there is a legitimate format / usage of the option that you specified. I'm not quite sure how to specify the parameters in the url with the /getname/* option. The other option was /getname?name=jim&zip=91001 Don't know how to implement the other. Share this post Link to post
JIMSMITH 0 Posted September 23 4 hours ago, hsvandrew said: Hi Jim, To handle parameters built into the URL rather than as query parameters you'll need to do the following: Assign a partial path to the 'pathInfo' of your WebModule Action i.e. /getname/* Then, in your ActionHandler you'll want to access the path part of the URL, break it into an array split by / and then execute based on the parts that matter var paths: TArray<string> = Request.PathInfo.split(['/']); //Check array length etc if sameText(paths[2],'add') then //Do add function else if sameText(paths[2],'delete') then //Do add function object.delete( paths[3] ); Hope that makes sense. I haven't tested this exact code so there might be slight syntax issues. I was never able to trigger the action with this implementation. I will try again. I don't think that I tried it properly. Share this post Link to post