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) :)
- Creates a pre-configured OWIN self host with the default routes already added.
- Supports configuring the OWIN pipeline
- Write your controllers as scripts
- Automatically imports common web api namespaces for you.
- Create a new folder for your script i.e. c:\hellowebapi and change to it.
- Install the Web API script pack
scriptcs -install -pre ScriptCs.WebApi2 - Create a start.csx and paste the code below
usingSystem.Dynamic;publicclassTestController:ApiController{publicdynamicGet(){dynamicobj=newExpandoObject();obj.message="Hello from Web Api";returnobj;}}varwebapi=Require<WebApi>();varserver=webapi.Configure(typeof(TestController)).UseJsonOnly().Start("http://localhost:8080");Console.WriteLine("Listening...");Console.ReadLine();server.Dispose();- Running as admin type
scriptcs start.csx -modules monoon Windows orscriptcs start.csxon Mac/Linux to launch the app. - Open a browser to "http://localhost:8080/api/test";
- That's it, your API is up!
You can configure the OWIN host by passing in an Action<IAppBuilder> to the Configure method
varserver=webapi.Configure(typeof(TestController),
builder=>{builder.Use<MyMiddleware>();}).Start("http://localhost:8080");