Is there any guide or documentation to build a REST API using Mono console or MonoDevelop. I tried to create MVC application in MonoDevelop however couldn't find App_Start/WebApiConfig.cs or relevant files by which I can define routes and other settings which I usually do in Visual studio based application.
Short answer is there is no template in MD for this, however it's very easy to get going:
Something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace MyWebApi
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// TODO: Add any additional configuration code.
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
For example:
protected void Application_Start (Object sender, EventArgs e)
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
Hope this help, M.
I followed the instructions given in @muszeo's answer and it worked.
I've created a sample project at https://github.com/sashoalm/HelloWebApi. It defines a single controller called HelloWebApiController, which creates an endpoint at http://localhost:8080/api/HelloWebApi that returns a string with "hello, world".
I've tested it on Linux with MonoDevelop 5.10.
You can clone it using git clone https://github.com/sashoalm/HelloWebApi.git
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With