I'm wondering if it's possible to implement a REST API endpoint in ASP.NET where a URL parameter can be passed in like a switch (as opposed to having to pass in a boolean parameter that has to be explicitly set in the URL to true or false).
I have this controller:
[Route("[controller]")]public class TestController : Controller { [HttpGet("example")] public IActionResult Example([FromQuery] bool? myswitch) { return Ok(new { ParameterValue = myswitch ?? false, Message = myswitch.HasValue && myswitch.Value ? "Parameter is present" : "Parameter is absent/false" }); }}
If I pass in http://localhost:5005/test/example?myswitch
I want to receive:
{"parameterValue": true,"message": "Parameter is present"}
But instead, I'm receiving:
{"parameterValue": false,"message": "Parameter is absent/false"}
Is there a different data type than boolean I could use for this purpose?