Reputation: 93
im making an Alexa skill to give information about meals. With this skill users will be able to ask for a menu's. They can ask for just a menu or they can ask for a specific menu like a breakfast menu. But I want the breakfast parameter and a parameter for the type of menu like a dessert menu to be optional. I now send a GET request to the url: .../Day/(day)/Slot/(slot)/Type/(type). In this url I want the slot and the type parameter to be empty.
My code now: The controller:
[HttpGet]
[Route("something/Day/{day:datetime}/Slot/{slotId:long?}/Type/{typeId:long?}")]
public async Task<List<something>> GetMeals(LocalDate day, long slotId = 1, long? typeId = null)
The request finds the controller when both parameters are not null or when only the typeId parameter is null. But when both or null or when only the slotId parameter is null the request doesn't find the controller. When both parameters are null the request looks like this: "something/Day/2020-02-20/Slot//Type/"
I can't change the route because the endpoint is used by other applications.
What am I doing wrong? Thanks for you help.
Upvotes: 0
Views: 1081
Reputation: 9490
You could modify the route
[HttpGet]
[Route("something/Day/{day:datetime}")]
public async Task<List<something>> GetMeals(LocalDate day, long? slotId = 1, long? typeId = null)
Example of use:
something/Day/2020-03-25/?slotId=1&typeId=2
An attempt to create a route with two slashes does not work. The route template separator character '/' cannot appear consecutively. It must be separated by either a parameter or a literal value.
[Route("/test/something/Day/{day:datetime}/Slot//Type/{typeId:long?}")] // does not work
Upvotes: 1