ASP.NET Web API 2.0 provides various new features and one of which is Attribute Routing. Attribute routing allows custom configuration for routing by assigning attribute to the web method.
Get latest version of ASP.NET Web API 2.0 via Nuget package
Apart from using attributes to define an uri for controller methods, Route Prefixes can be defined as a controller attribute that will become base uri for for all of the controller methods.
Do you realize if it weren't for Edison we'd be watching TV by candlelight.
Al Boliska
Get latest version of ASP.NET Web API 2.0 via Nuget package
Install-Package Microsoft.AspNet.WebApi.WebHostUpdate WebApiConfig to include config.MapHttpAttributeRoutes()
public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } }The [HttpGet] attribute defines an HTTP GET method. Now create RESTful endpoint using web api
[HttpGet("api/invoice/scan/{id}")] public HttpResponseMessage GetScannedInvoiceById(string id) { HttpResponseMessage result = new HttpResponseMessage(); string isPath = GetInoviceScanPath(id); result.Content = new StreamContent(new FileStream(isPath, FileMode.Open)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return result; }http://localhost/csharptechies/api/invoice/scan/1908765 will now get the image as HttpResponseMessage.
Apart from using attributes to define an uri for controller methods, Route Prefixes can be defined as a controller attribute that will become base uri for for all of the controller methods.
Do you realize if it weren't for Edison we'd be watching TV by candlelight.
Al Boliska