All the examples of WebAPI I have seen show how to have a basic CRUD setup with a controller. For example the controller below shows a controller for campaigns in my application:
public IEnumerable<CampaignModel> Get()
{
return _campaignService.GetAll();
}
public CampaignModel Get(int id)
{
return _campaignService.GetByID(id);
}
public void Post(CampaignModel campaign)
{
_campaignService.Create(campaign);
}
public void Put(CampaignModel campaign)
{
_campaignService.Update(campaign);
}
public void Delete(int id)
{
_campaignService.Delete(id);
}
This is all well and good, and I end up with a few nice endpoints in the following format:
- GET campaigns/
- GET campaigns/{id}
- POST campaigns/{campaign}
- PUT campaigns/{campaign}
- DELETE campaigns/{id}
However, I now want to extend the api further and add the following endpoints:
- POST campaigns/send
- POST campaigns/schedule/{date}
Is it possible to have these as part of the same controller as the CRUD actions above? Or do I have to add other controllers to and then set up a route for each of these endpoints?
Check out “Routing by Action Name” over here
will map to “api/campaigns/send” and “api/campaigns/schedule”