Skip to content

Commit 25b559d

Browse files
committed
Merge branch 'dev' of github.com:glennblock/scriptcs-webapi into dev
2 parents febfd0c + 8fe2fbd commit 25b559d

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

README.md

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,53 @@ Makes using ASP.NET Web API's self host with scriptcs easy as cake, much easier
88

99
## Highlights:
1010

11-
* Creates a pre-configured self host with the default route already added.
12-
* Configures to allow resolving script controllers.
11+
* Creates a pre-configured OWIN self host with the default routes already added.
12+
* Supports configuring the OWIN pipeline
13+
* Write your controllers as scripts
1314
* Automatically imports common web api namespaces for you.
14-
* Works as self hosted server or in OWIN
1515

1616
## Getting started with Web API using the pack
1717

18-
Disclaimer: Ultimately (soon) you will be able to install this via nuget and not have to clone / build / copy
19-
2018
* Create a new folder for your script i.e. c:\hellowebapi and change to it.
21-
* Install the Web API script pack ```scriptcs -install -pre ScriptCs.WebApi```
19+
* Install the Web API script pack ```scriptcs -install -pre ScriptCs.WebApi2```
2220
* Create a start.csx and paste the code below
2321

2422
```csharp
25-
public class TestController : ApiController {
26-
public string Get() {
27-
return "Hello world!";
28-
}
23+
using System.Dynamic;
24+
25+
public class TestController : ApiController
26+
{
27+
public dynamic Get() {
28+
dynamic obj = new ExpandoObject();
29+
obj.message = "Hello from Web Api";
30+
return obj;
31+
}
2932
}
3033

31-
var webApi = Require<WebApi>();
32-
var server = webApi.CreateServer("http://localhost:8080");
33-
server.OpenAsync().Wait();
34-
34+
var webapi = Require<WebApi>();
35+
36+
var server = webapi.
37+
Configure(typeof(TestController)).
38+
UseJsonOnly().
39+
Start("http://localhost:8080");
40+
3541
Console.WriteLine("Listening...");
3642
Console.ReadLine();
37-
server.CloseAsync().Wait();
43+
server.Dispose();
3844
```
39-
* Running as admin type ```scriptcs start.csx``` to launch the app.
45+
* Running as admin type ```scriptcs start.csx -modules mono``` on Windows or ```scriptcs start.csx``` on Mac/Linux to launch the app.
4046
* Open a browser to "http://localhost:8080/api/test";
4147
* That's it, your API is up!
4248

43-
Alternatively you can host the script pack in OWIN e.g.
44-
45-
```csharp
46-
public class TestController : ApiController {
47-
public string Get() {
48-
return "Hello world!";
49-
}
50-
}
51-
52-
Require<OwinSelfHost>();
53-
54-
var webApi = Require<WebApi>();
55-
var config = webApi.Create();
56-
57-
using ( OwinSelfHost.CreateServer("http://localhost:8080", app => app.UseWebApi(config)) ) {
58-
Console.WriteLine("Listening...");
59-
Console.ReadLine();
60-
}
61-
```
62-
63-
6449
## Customizing
65-
You can customize the host by modifying the configuration object.
66-
Or if you would like to pass your own you can use the `CreateServer` overload.
67-
Additional `CreateServer` overloads allow you to explicitly specify assemblies or `IHttpController` types you want to expose in your api:
68-
50+
You can configure the OWIN host by passing in an `Action<IBuilder>` to the `Configure` method
6951
```csharp
70-
// Use a custom configuration and specify controller types.
71-
var config = new HttpSelfHostConfiguration("http://localhost:8080");
72-
var controllers = new List<Type> { typeof(TestController) };
73-
var server = webApi.CreateServer(config, controllers)
52+
var server = webapi.
53+
Configure(
54+
typeof(TestController),
55+
builder=> {
56+
builder.Use<MyMiddleware>();
57+
}
58+
).
59+
Start("http://localhost:8080");
7460
```
75-
76-
## What's next
77-
TBD

0 commit comments

Comments
 (0)