I created an asp.net web api 2 controller to manage a logical asset. As usual, the post creates it and returns uri to the asset, and deleting removes it, but I have 2 puts to perform separate actions on the asset, so my code looks like this:
public class Controller : ApiController { public IHttpActionResult Post(Stuff stuff) { var id = CreateNewStuff(stuff); return CreatedAtRoute("DefaultApi", new { id = this.id }, id); } [HttpPut] public IHttpActionResult ActionA(int id, ActionAStuff stuff) {
In order for this routing to understand this, my routing rules (including the default rule):
config.Routes.MapHttpRoute(name: "ActionApi", routeTemplate: "api/{controller}/{action}/{id}"); config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional });
This works and feels that the system neatly splits put code into an action and ensures that the system rejects requests for actions that we do not support.
The problem is that the client who creates the asset via mail does not know what the ur (put) of the action (action) is, how it is done for the uri asset through the location header returned from the message. If we change the form of the uri in the future, the clients will break because they will manually create the uris.
What is the correct way to either return multiple service uris from the message, or simply do the above.
asp.net-mvc asp.net-web-api
John freebs
source share