Abrar
Abrar6mo ago

Validating the existence of query string parameters

So I'm relaying a call to an api which accepts a bunch of optional query params.... When i make the API call... I try to pass on the query params like so...
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date,
"party" : ctx["root"]["request"]["query"].party,
"state" : ctx["root"]["request"]["query"].state,
"search" : ctx["root"]["request"]["query"].search
}
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date,
"party" : ctx["root"]["request"]["query"].party,
"state" : ctx["root"]["request"]["query"].state,
"search" : ctx["root"]["request"]["query"].search
}
I'm looking for a simple in-line way to validate the existence of each param, and only then and only populate the value.. Does anyone know how to do this in a clean and efficient manner? (NB: im not a javascript guru) Thanks in advance
Solution:
Alternately you can use the API call to pass multiple parameter at one to your API
No description
Jump to solution
3 Replies
Abrar
Abrar6mo ago
further more ... I have developed the following :
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date ? ctx["root"]["request"]["query"].date : "",
"party" : ctx["root"]["request"]["query"].party ? ctx["root"]["request"]["query"].party : "",
"state" : ctx["root"]["request"]["query"].state ? ctx["root"]["request"]["query"].state : "",
"search" : ctx["root"]["request"]["query"].search ? ctx["root"]["request"]["query"].search : ""
}
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date ? ctx["root"]["request"]["query"].date : "",
"party" : ctx["root"]["request"]["query"].party ? ctx["root"]["request"]["query"].party : "",
"state" : ctx["root"]["request"]["query"].state ? ctx["root"]["request"]["query"].state : "",
"search" : ctx["root"]["request"]["query"].search ? ctx["root"]["request"]["query"].search : ""
}
but is there a cleaner way?
Gaurav Chadha
Gaurav Chadha6mo ago
Hi @Abrar, You can pass the query params from the request body as variable.
No description
Solution
Gaurav Chadha
Gaurav Chadha6mo ago
Alternately you can use the API call to pass multiple parameter at one to your API
No description