dimanche 26 avril 2015

How define a WebApi route to access method

I'd like have access to a method other than "GET", "PUSH", "PATCH", ....

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "Employee",
            routeTemplate: "api/employee/{employeeid}",
            defaults: new { controller = "employee", employeeid = RouteParameter.Optional }
        );
    }
}

I have access to the employee controller :

    [RoutePrefix("api/employee")]
    public class EmployeeController : ApiController
    {
        public HttpResponseMessage Get() { }
        public HttpResponseMessage Get(int employeeid) {}
        public HttpResponseMessage Post([FromBody] EmployeeModel model){}

        [HttpPut]
        [HttpPatch]
        public HttpResponseMessage Patch([FromBody] EmployeeModel model){}

        [Route("create")]
        public HttpResponseMessage Create() {}
    }

That's work I have access to the method

http://localhost/employee
http://localhost/employee/1

I'd like have access to the "Create" method :

http://localhost/employee/create

I tried to add another route but without success.

What can I do to have access to "Create" method and of course without any impact when I call the other methods.

Thanks,

Aucun commentaire:

Enregistrer un commentaire