How to build minimalistic REST server in .Net
Install “Microsoft ASP.NET Web API Self Host” and all of its dependencies via NuGet.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.SelfHost; namespace resttest { public class ExampleData { public int Id { get; set; } } public class ExampleController : ApiController { // /api/job public IEnumerable<ExampleData> Get() { return new List<ExampleData>() { new ExampleData(){ Id = 2 }, new ExampleData(){ Id = 4 } }; } // /api/job/3 public ExampleData Get(int id) { return new ExampleData() { Id = 3 }; } } class Program { static void Main(string[] args) { var configuration = new HttpSelfHostConfiguration("http://localhost:1337"); //Setup the routes configuration.
[Read More]