Thank you for supporting the Cloud Customer Connect Community in 2024. It's a gift to work with you!

Look back
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

How to validate path variable/Uri parameter

edited Feb 17, 2017 8:00AM in Digital Assistant & Mobile 8 comments

Summary

How to validate path variable/Uri parameter

Content

Hi ,
I have a Custom Api with method as GET , passing the parameter along with the url . Could you please suggest a method to check whether the parameter is null or not ?

Below given my code .

<span class="pln">service</span><span class="pun">.</span><span class="kwd">get</span><span class="pun">(</span><span class="str">'/mobile/custom/****/deviceVersion/:deviceType'</span><span class="pun">,</span><span class="kwd">function</span><span class="pun">(</span><span class="pln">req</span><span class="pun">,</span><span class="pln">res</span><span class="pun">){</span><span class="pln"><br/>             </span><span class="kwd">var</span><span class="pln"> reqParams </span><span class="pun">=</span><span class="pln"> req</span><span class="pun">.</span><span class="pln">params</span><span class="pun">;</span><span class="pln"><br/>             </span><span class="kwd">var</span><span class="pln"> finalResponse</span><span class="pun">;</span><span class="pln"><br/>             </span><span class="kwd">var</span><span class="pln"> params</span><span class="pun">=</span><span class="str">'/'</span><span class="pun">+</span><span class="pln">reqParams</span><span class="pun">.</span><span class="pln">deviceType</span><span class="pun">;</span><span class="pln"><br/>             </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">reqParams</span><span class="pun">.</span><span class="pln">deviceType</span><span class="pun">==</span><span class="str">'{}'</span><span class="pun">){</span><span class="pln">   </span><span class="com">// ***Here is my problem***</span><span class="pln"><br/>                 finalResponse </span><span class="pun">=</span><span class="pln"> jbuilder</span><span class="pun">.</span><span class="pln">encode</span><span class="pun">(</span><span class="kwd">function</span><span class="pln"> </span><span class="pun">(</span><span class="pln">json</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>                      json</span><span class="pun">.</span><span class="kwd">set</span><span class="pun">(</span><span class="str">'Response'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pln"> </span><span class="pun">(</span><span class="pln">json</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>                      json</span><span class="pun">.</span><span class="kwd">set</span><span

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!