Question

For the GET function in my controller I want to require that a name be passed in. For the PUT function I want to require that the id be passed in (with the object in the message body). For example:

GetObject(string name)
PutObject(int id, Object obj)

Can I create a route that requires either the name or the id parameter to exist? In pseudocode:

routeTemplate: api/{controller}/{name}|{id}

Or what is the best way to route this?

Was it helpful?

Solution

I might suggest having a look at the AttributeRouting package to solve your problems if you're using HTTP verbs RESTfully. It allows for some pretty advanced routing including conditionals like you're looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top