How to get param passed in GET REST query
Hi,
I don't found how to get params send by a GET REST query (not in url but by request param).
this is config of the call in postman
I try to get %request.Data, doesn't work : Data is undefined
I try to get %request.GetCgiEnv("Data"), doesn't work, return ""
I do ZW %request and see that my parameter is present in cgi parameters, but I don't now how to access it.
I found a way by %request.Data("Top",1), but in this case, I get parameters one by one.
Is a method to get all my parameters in an object or an array exists ?
Hello Pierre,
You have two options to get query parameters
ClassMethod GetQueryParams() { set data="" For { set data = %request.Next(data) quit:data="" write data,! } } OUTPUT Bottom Name Top
For cgiEnvs. You can follow same merge option to get all values. Otherwise use %request.NextCgiEnv(cgi) to get the list of available values.
ClassMethod GetcgiEnvs() { set cgi="" for { set cgi = %request.NextCgiEnv(cgi) quit:cgi="" write cgi,! } }
Hi Ashok,
Thank you for your answer, I understand and will apply looping by Next in Data.
However, I don't know how to merge the entire %request.Data into local array and use string function.
I'm sorry for asking questions that should be obvious, but I'm new to Iris for REST Api...
Hello Pierre,
No problem. You can use the merge command(sorry not a string function) to take a copy of entire global node and subtree
merge queryparam = %request.Data zwrite queryparam ;print the entire node and subtree
Many thanks, works fine and it's exactly what I need
To check all parts of the request you can use this utility method which outputs all objects as a response. Just add this to any part of your code:
Hi Eduard,
Thanks for this utility method. I think I will use it for debugging
%request.Get("Top") will return the value which is stored in %request.Data("Top", 1).
If you want to iterate through all the values, I'd use @Ashok Kumar 's solution or $ORDER on %request.Data.
Hi Chad,
Thanks for your alternative syntax !