Skip to Main Content

Cloud Platform

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to validate path variable/Uri parameter

OTVianJan 31 2017 — edited Feb 17 2017

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 .

service.get('/mobile/custom/****/deviceVersion/:deviceType',function(req,res){
            
var reqParams = req.params;
            
var finalResponse;
            
var params='/'+reqParams.deviceType;
            
if(reqParams.deviceType=='{}'){   // ***Here is my problem***
                 finalResponse
= jbuilder.encode(function (json) {
                      json
.set('Response', function (json) {
                      json
.set('responseCode', '400');
                      json
.set('responseMessage', 'Malformed request query');
                 
});
           
});
            res
.status(400).send(finalResponse);
            res
.end();
           
}else{
        var connector='/deviceVersion';
       commonHandler
.CommonHandlerGetMethodFunction(req,res,connector,params);
  
}

});

I have tried the following

1. if(reqParams.deviceType=='{}'){}

2. if(JSON.Stringify(reqParams.deviceType)=='{}'){}

3. if(JSON.Stringify(reqParams.deviceType).length==0){}

Also is there anyway to debug the code other than using console?

The error that i am getting is

{
  
"type": "w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
  
"status": 404,
  
"title": "API not found",
  
"detail": "We cannot find the API ******/1.0 for the provided URL path /deviceVersion/. Verify your request parameters and try again.",
  
"o:ecid": "005Hp2YhoPF3j4C_nDs1yZ000Uba00001w, 0:3",
  
"o:errorCode": "MOBILE-57945",
  
"o:errorPath": "/mobile/custom/******/deviceVersion/"
}

@"Tware-Oracle" , @"Chris Muir-Oracle" could you please help me with this ?

This post has been answered by User_HWHT9 on Feb 14 2017
Jump to Answer

Comments

Processing