I have an action with two required and a few optional parameters:
[HttpGet]
public IHttpActionResult GetUsers(DateTime dateFrom, DateTime dateTo, string zipcode, int? countryId)
{
using (DataHandler handler = new DataHandler())
return Ok(handler.GetUsers(dateFrom, dateTo).ToList());
}
I want an url like this one:
/api/getusers/2018-12-03T07:30/2018-12-03T12:45?zipcode=4002&countryId=4
zipcode and countryId are optional and will be added with the ?-thingy. The required parameters dateFrom and dateTo will be added with /
so following urls should be possible too:
/api/getusers/2018-12-03T07:30/2018-12-03T12:45?countryId=4
/api/getusers/2018-12-03T07:30/2018-12-03T12:45?zipcode=4002
/api/getusers/2018-12-03T07:30/2018-12-03T12:45
I tried a few routings like
[Route("getusers/{dateFrom}/{dateTo}")]
[Route("getusers/{dateFrom}/{dateTo}*")]
[Route("getusers/{dateFrom}/{dateTo}**")]
[Route("getusers/{dateFrom}/{dateTo}?zipcode={zipcode}&countryId={countryId}")]
but none of them are working. When I remove the optional parameters it works, but I need those optional ones.
Any idea how to get this done?