scriptcs-contrib / scriptcs-webapi

Script pack for web api
Other
24 stars 8 forks source link

scriptcs-webapi

Web API Script Pack

What is it?

Makes using ASP.NET Web API's self host with scriptcs easy as cake, much easier than [this] (https://github.com/scriptcs/scriptcs-samples/tree/master/webapihost) :)

Highlights:

Getting started with Web API using the pack

using System.Dynamic;

public class TestController : ApiController
{
    public dynamic Get() {
        dynamic obj = new ExpandoObject();
        obj.message = "Hello from Web Api";
        return obj;
    }
}

var webapi = Require<WebApi>();

var server = webapi.
    Configure(typeof(TestController)).
    UseJsonOnly().
    Start("http://localhost:8080");

Console.WriteLine("Listening...");
Console.ReadLine();
server.Dispose();

Customizing

You can configure the OWIN host by passing in an Action<IAppBuilder> to the Configure method

var server = webapi.
    Configure(
        typeof(TestController),
        builder=> {
          builder.Use<MyMiddleware>();
        }
    ).
    Start("http://localhost:8080");