Skip to content

Commit

Permalink
Reverting RegEx
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Apr 12, 2016
1 parent 6c12530 commit 2ee0732
Show file tree
Hide file tree
Showing 8 changed files with 495 additions and 497 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,25 @@ namespace Company.Project
REST API Example:
-----------------

The WebApi module supports two routing strategies: Wildcard and RegEx. By default, and in order to maintain backwards compatibility, the WebApi module will use the **Wildcard Routing Strategy** and match routes using the asterisk `*` character in the route. **For example:**
The WebApi module supports two routing strategies: Wildcard and Regex. By default, and in order to maintain backwards compatibility, the WebApi module will use the **Wildcard Routing Strategy** and match routes using the asterisk `*` character in the route. **For example:**
- The route `/api/people/*` will match any request with a URL starting with the two first URL segments `api` and `people` and ending with anything. The route `/api/people/hello` will be matched.
- You can also use wildcards in the middle of the route. The route `/api/people/*/details` will match requests starting with the two first URL segments `api` and `people`, and ending with a `details` segment. The route `/api/people/hello/details` will be matched.

*Note that most REST services can be designed with this simpler Wildcard routing startegy. However, the RegEx matching strategy is the current recommended approach as we might be deprecating the Wildcard strategy altogether*
*Note that most REST services can be designed with this simpler Wildcard routing startegy. However, the Regex matching strategy is the current recommended approach as we might be deprecating the Wildcard strategy altogether*

On the other hand, the **RegEx Routing Strategy** will try to match and resolve the values from a route template, in a similar fashion to Microsoft's Web API 2. A method with the following route `/api/people/{id}` is going to match any request URL with three segments: the first two `api` and `people` and the last one is going to be parsed or converted to the type in the `id` argument of the handling method signature. Please read on if this was confusing as it is much simpler than it sounds. Additionally, you can put multiple values to match, for example `/api/people/{mainSkill}/{age}`, and receive the parsed values from the URL straight into the arguments of your handler method.
On the other hand, the **Regex Routing Strategy** will try to match and resolve the values from a route template, in a similar fashion to Microsoft's Web API 2. A method with the following route `/api/people/{id}` is going to match any request URL with three segments: the first two `api` and `people` and the last one is going to be parsed or converted to the type in the `id` argument of the handling method signature. Please read on if this was confusing as it is much simpler than it sounds. Additionally, you can put multiple values to match, for example `/api/people/{mainSkill}/{age}`, and receive the parsed values from the URL straight into the arguments of your handler method.

*During server setup:*

```csharp
// The routing strategy is Wildcard by default, but you can change it to RegEx as follows:
var server = new WebServer("http://localhost:9696/", new NullLog(), RoutingStrategy.RegEx);
// The routing strategy is Wildcard by default, but you can change it to Regex as follows:
var server = new WebServer("http://localhost:9696/", new NullLog(), RoutingStrategy.Regex);

server.RegisterModule(new WebApiModule());
server.Module<WebApiModule>().RegisterController<PeopleController>();
```

*And our controller class (using RegEx Strategy) looks like:*
*And our controller class (using Regex Strategy) looks like:*

```csharp
public class PeopleController : WebApiController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Unosquare.Tubular, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Tubular.ServerSide.0.9.42\lib\net45\Unosquare.Tubular.dll</HintPath>
<HintPath>..\packages\Tubular.ServerSide.0.9.47\lib\net45\Unosquare.Tubular.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Unosquare.Labs.EmbedIO.Samples/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<package id="log4net" version="2.0.5" targetFramework="net45" />
<package id="System.Linq.Dynamic.Library" version="1.1.14" targetFramework="net45" />
<package id="Tubular" version="0.9.45" targetFramework="net45" />
<package id="Tubular.ServerSide" version="0.9.42" targetFramework="net45" />
<package id="Tubular.ServerSide" version="0.9.47" targetFramework="net45" />
</packages>
4 changes: 2 additions & 2 deletions Unosquare.Labs.EmbedIO.Tests/RegExRoutingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Unosquare.Labs.EmbedIO.Tests
{
[TestFixture]
public class RegExRoutingTest
public class RegexRoutingTest
{
protected WebServer WebServer;
protected TestConsoleLog Logger = new TestConsoleLog();
Expand All @@ -18,7 +18,7 @@ public class RegExRoutingTest
public void Init()
{
WebServer =
new WebServer(Resources.ServerAddress, Logger, RoutingStrategy.RegEx)
new WebServer(Resources.ServerAddress, Logger, RoutingStrategy.Regex)
.WithWebApiController<TestRegexController>();
WebServer.RunAsync();
}
Expand Down
200 changes: 100 additions & 100 deletions Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2E100548-08CD-4EFD-AD08-AF584081B098}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Unosquare.Labs.EmbedIO.Tests</RootNamespace>
<AssemblyName>Unosquare.Labs.EmbedIO.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CorsModuleTest.cs" />
<Compile Include="FluentTest.cs" />
<Compile Include="LocalSessionModuleTest.cs" />
<Compile Include="MiddlewareTest.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="RegExRoutingTest.cs" />
<Compile Include="StaticFilesModuleTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestObjects\PeopleRepository.cs" />
<Compile Include="TestObjects\TestConsoleLog.cs" />
<Compile Include="TestObjects\TestController.cs" />
<Compile Include="TestObjects\TestHelper.cs" />
<Compile Include="TestObjects\TestMiddleware.cs" />
<Compile Include="TestObjects\TestRegexController.cs" />
<Compile Include="TestObjects\TestWebModule.cs" />
<Compile Include="TestObjects\TestWebSocket.cs" />
<Compile Include="WebApiModuleTest.cs" />
<Compile Include="WebServerCultureTest.cs" />
<Compile Include="WebServerTest.cs" />
<Compile Include="WebSocketsModuleTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Unosquare.Labs.EmbedIO\Unosquare.Labs.EmbedIO.csproj">
<Project>{7d7c29b4-9493-4ebd-8f20-6fac1e7161ee}</Project>
<Name>Unosquare.Labs.EmbedIO</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="html\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2E100548-08CD-4EFD-AD08-AF584081B098}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Unosquare.Labs.EmbedIO.Tests</RootNamespace>
<AssemblyName>Unosquare.Labs.EmbedIO.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CorsModuleTest.cs" />
<Compile Include="FluentTest.cs" />
<Compile Include="LocalSessionModuleTest.cs" />
<Compile Include="MiddlewareTest.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="RegexRoutingTest.cs" />
<Compile Include="StaticFilesModuleTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestObjects\PeopleRepository.cs" />
<Compile Include="TestObjects\TestConsoleLog.cs" />
<Compile Include="TestObjects\TestController.cs" />
<Compile Include="TestObjects\TestHelper.cs" />
<Compile Include="TestObjects\TestMiddleware.cs" />
<Compile Include="TestObjects\TestRegexController.cs" />
<Compile Include="TestObjects\TestWebModule.cs" />
<Compile Include="TestObjects\TestWebSocket.cs" />
<Compile Include="WebApiModuleTest.cs" />
<Compile Include="WebServerCultureTest.cs" />
<Compile Include="WebServerTest.cs" />
<Compile Include="WebSocketsModuleTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Unosquare.Labs.EmbedIO\Unosquare.Labs.EmbedIO.csproj">
<Project>{7d7c29b4-9493-4ebd-8f20-6fac1e7161ee}</Project>
<Name>Unosquare.Labs.EmbedIO</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="html\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>
2 changes: 1 addition & 1 deletion Unosquare.Labs.EmbedIO/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,6 @@ public enum RoutingStrategy
/// <summary>
/// The Regex strategy
/// </summary>
RegEx
Regex
}
}
Loading

0 comments on commit 2ee0732

Please sign in to comment.