I would like to route requests to different actions based on the value of a particular json parameter.
For example, given the following json data:
{
type: "type1",
type1data: "type1value"
}
and
{
type: "type2",
type2data: "type2value"
}
I'd like to be able to have 2 different actions on my ApiController:
void CreateType1(string type1data)
{
// ...
}
void CreateType2(string type2data)
{
//...
}
How can something like this be done?
Update:
I'd like the same URL if possible. Something like /objects/create
.
I'd much rather use a custom ApiControllerActionSelector.
Here is the model. I gave it a weird name of Abc.
Here is the action method.
Finally, plug-in the action selector.
If you now POST to http://localhost:port/api/yourapicontroller, depending on the value in type field in JSON, the action method Create* will be selected.
Something like this. For simplicity, this example is not a proper async implementation.