public IHttpActionResult Get() { var headers = Request.Headers; //Do something with the headers... return Ok(); }
public IHttpActionResult Post([FromBody] MyModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //Do something with the model... return Ok(); }
public IHttpActionResult Get(int id) { var routeData = Request.GetRouteData(); var routeId = routeData.Values["id"]; //Do something with the route data... return Ok(); }In this example, we are using the HttpControllerContext.Request.GetRouteData() method to retrieve the values of the route parameters. All these examples belong to the System.Web.Http.Controllers package in C#.