Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

ASP.Net Web API Optional Boolean Param

I am trying to use an optional boolean parameter to a web endpoint and I am using swagger.   I have tried {isActive?} then bool? or bool = false etc. and everytime no matter what when I select true in swagger it passes false.   If I make it {isActive} then bool it seems to work by in Swagger it is defaulted to true and when I click execute it shows a validation red and won't pass unless I change it to false then back to true.

How can I best pass an optional boolean and is there something for swagger I need to do to get it to behave properly?

Thanks all
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbornstein2
sbornstein2

ASKER

So you think it is better to say have two endpoints for each one one for every endpoint an all endpoint and one for only active?   /Customer and /Customer/active for example?

I understand what you are saying but is it cleaner to have on a swagger api site duplicate endpoints for every one I want to have the option to only select active records?
Okay, what kind of API?

Cause this seems not to be an optional parameter, but a filter. So  /Customers?active=1 or /Customers?active=0 (or using true/false instead of 1/0).