Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple NULL values in Web API Get Method Parameter

Tags:

c#

.net

get

api

I have this kind of sample code below that calls an API using get method:

CrudService.getAll("sampleurl/param1/param2/param3");

From that sample, param1 and param2 can be null/blank value. What happens is that the value of param3 goes to param1 when it comes to the API Controller.

How can I maintain the right values for the parameter even if there can be several null/blank values? TIA.

like image 577
Stuart Avatar asked Dec 03 '22 19:12

Stuart


1 Answers

CrudService.getAll("sampleurl/param1/param2/param3");

You have to pass a dummy value for param1 so if param1 is empty keep it "param1". various possible call based on empty params :

  • ("sampleurl/param1/param2/2");

  • ("sampleurl/param1/3/2");

  • ("sampleurl/param1/param2/param3");

So when the call goes to API, check there is param1=param1 ignore the value you have to keep 3 values in order to match the signature of API in any case.

like image 200
Jin Thakur Avatar answered Dec 06 '22 08:12

Jin Thakur