diff --git a/.gitignore b/.gitignore index c7b7122..b1df3dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -packages +/packages +node_modules +bin +obj +*.suo +*.csproj.user + diff --git a/README.md b/README.md index f378eee..751a1a7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ connect-owin Samples Repository =============================== + +# ASP.NET WebApi Sample + + $ cd Samples.WebApi + $ msbuild Samples.WebApi.csproj + $ npm install + $ node server.js + +Open http://localhost:3000/Api/Hello/World + diff --git a/Samples.WebApi.sln b/Samples.WebApi.sln new file mode 100644 index 0000000..7142f4c --- /dev/null +++ b/Samples.WebApi.sln @@ -0,0 +1,33 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E526A334-884E-43C0-8293-0829C9EB80AC}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".node", ".node", "{DCCEC959-C45D-436F-AB69-0204FF8D83FD}" + ProjectSection(SolutionItems) = preProject + Samples.WebApi\package.json = Samples.WebApi\package.json + Samples.WebApi\server.js = Samples.WebApi\server.js + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.WebApi", "Samples.WebApi\Samples.WebApi.csproj", "{4A3E58EA-729C-4527-8AA4-DFCD402B810E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4A3E58EA-729C-4527-8AA4-DFCD402B810E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A3E58EA-729C-4527-8AA4-DFCD402B810E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A3E58EA-729C-4527-8AA4-DFCD402B810E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A3E58EA-729C-4527-8AA4-DFCD402B810E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples.WebApi/Config/WebApiConfig.cs b/Samples.WebApi/Config/WebApiConfig.cs new file mode 100644 index 0000000..dc09554 --- /dev/null +++ b/Samples.WebApi/Config/WebApiConfig.cs @@ -0,0 +1,29 @@ +using System.Web.Http; +using System.Net.Http.Formatting; +using Newtonsoft.Json; + +namespace Samples.WebApi.Config +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{action}/" + ); + + // Configure JSON formatter + config.Formatters.Clear(); + config.Formatters.Add(new JsonMediaTypeFormatter() + { + SerializerSettings = new JsonSerializerSettings() + { +#if DEBUG + Formatting = Formatting.Indented +#endif + } + }); + } + } +} diff --git a/Samples.WebApi/Controllers/HelloController.cs b/Samples.WebApi/Controllers/HelloController.cs new file mode 100644 index 0000000..88369d7 --- /dev/null +++ b/Samples.WebApi/Controllers/HelloController.cs @@ -0,0 +1,24 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Web.Http; + +namespace Samples.WebApi.Controllers +{ + public class HelloController : ApiController + { + // GET Api/Hello/World/ + [HttpGet] + [ActionName("World")] + public HttpResponseMessage HelloWorld() + { + HttpResponseMessage response = new HttpResponseMessage(); + response.Content = new StringContent("Hello world!"); + response.Headers.CacheControl = new CacheControlHeaderValue(); + response.Headers.CacheControl.MustRevalidate = true; + response.Headers.CacheControl.MaxAge = TimeSpan.Zero; + response.Headers.CacheControl.Private = true; + return response; + } + } +} diff --git a/Samples.WebApi/Samples.WebApi.csproj b/Samples.WebApi/Samples.WebApi.csproj new file mode 100644 index 0000000..ea39c03 --- /dev/null +++ b/Samples.WebApi/Samples.WebApi.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {4A3E58EA-729C-4527-8AA4-DFCD402B810E} + Library + Properties + Samples.WebApi + Samples.WebApi + v4.5 + 512 + .\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\packages\Microsoft.Owin.1.1.0-beta2\lib\net45\Microsoft.Owin.dll + + + False + ..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll + + + False + ..\packages\Owin.1.0\lib\net40\Owin.dll + + + + + + False + ..\packages\Microsoft.AspNet.WebApi.Client.5.0.0-beta2\lib\net45\System.Net.Http.Formatting.dll + + + False + ..\packages\Microsoft.AspNet.WebApi.Core.5.0.0-beta2\lib\net45\System.Web.Http.dll + + + False + ..\packages\Microsoft.AspNet.WebApi.Owin.5.0.0-beta2\lib\net45\System.Web.Http.Owin.dll + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples.WebApi/Startup.cs b/Samples.WebApi/Startup.cs new file mode 100644 index 0000000..066138f --- /dev/null +++ b/Samples.WebApi/Startup.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Web.Http; +using Owin; +using Samples.WebApi.Config; + +namespace Samples.WebApi +{ + public class Startup + { + public static void Configuration(IAppBuilder app) + { + HttpConfiguration config = new HttpConfiguration(); + WebApiConfig.Register(config); + app.UseWebApi(config); + } + } +} diff --git a/Samples.WebApi/package.json b/Samples.WebApi/package.json new file mode 100644 index 0000000..eaa1859 --- /dev/null +++ b/Samples.WebApi/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "connect-owin": "0.0.1" + }, + "devDependencies": { + "express": "~3.4.0" + } +} \ No newline at end of file diff --git a/Samples.WebApi/packages.config b/Samples.WebApi/packages.config new file mode 100644 index 0000000..2b8066e --- /dev/null +++ b/Samples.WebApi/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Samples.WebApi/server.js b/Samples.WebApi/server.js new file mode 100644 index 0000000..49c96a5 --- /dev/null +++ b/Samples.WebApi/server.js @@ -0,0 +1,9 @@ +var owin = require('connect-owin'), + express = require('express'); + +var app = express(); +app.all('/Api/*', owin(__dirname + '\\bin\\Debug\\Samples.WebApi.dll')); +app.all('/node', function (req, res) { + res.send(200, 'Hello from JavaScript! Time on server ' + new Date()); +}); +app.listen(3000);