Compass.NET 1.0.0-preview1

This is a prerelease version of Compass.NET.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Compass.NET --version 1.0.0-preview1                
NuGet\Install-Package Compass.NET -Version 1.0.0-preview1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Compass.NET" Version="1.0.0-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Compass.NET --version 1.0.0-preview1                
#r "nuget: Compass.NET, 1.0.0-preview1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Compass.NET as a Cake Addin
#addin nuget:?package=Compass.NET&version=1.0.0-preview1&prerelease

// Install Compass.NET as a Cake Tool
#tool nuget:?package=Compass.NET&version=1.0.0-preview1&prerelease                

Compass.NET Build status AppVeyor tests Coverage Status GitHub last commit (branch) Nuget (with prereleases)

Simple HTTP request router for .NET backends

This documentation refers the PREVIEW version of library so the API is subject to change

How to use

This library comes with an extremely simple API set (consits of a few methods only)

  1. Register the known routes

     using System.Net;
     using Solti.Utils.Router;
    
     RouterBuilder routerBuilder = new
     (
     	// This handler is called on every unknown routes
     	defaultHandler: (object? state) =>
     	{
     		HttpListenerContext ctx = (HttpListenerContext) state;
     		...
     	},
     	// can be omitted
     	converters: DefaultConverters.Instance
     );
     routerBuilder.AddRoute
     (
     	// A route may contain parameter(s)
     	route: "/get/picture-{id:int}",
     	handler: (IReadOnlyDictionary<string, object?> paramz, object? state) =>
     	{
     		HttpListenerContext ctx = (HttpListenerContext) state;
     		int id = (int) paramz["id"];
     		...
     	},
     	// "GET" is the default
     	"GET", "OPTIONS"
     );
    

    A valid route looks like [/]segment1/[prefix]{paramName:converter[:style]}[suffix]/segment3[/]

  2. Build the router delegate and start the HTTP backend

     Router route = routerBuilder.Build();
    
     HttpListener listener = new HttpListener();
     listener.Prefixes.Add("http://localhost:8080/");
     listener.Start();
     ...
     while (Listener.IsListening)  // probably this will run in a separate thread
     {
     	HttpListenerContext context = Listener.GetContext();
     	route(context, context.Request.Url!.AbsolutePath, context.Request.HttpMethod);
     }
    

For a more comprehensive example check out the use cases fixture

Converters

Converters are used to parse the variable value coming from the request path. Default converters (int, guid, str) can be accessed via the DefaultConverters.Instance property.

using Solti.Utils.Router;

RouterBuilder routerBuilder = new
(
	defaultHandler: (object? state) => {...},
	converters: new Dictionary<string, ConverterFactory>(DefaultConverters.Instance)
	{
		{"mytype", (string? style) => MyTypeConverter}
	}
);

bool MyTypeConverter(string input, out object? val) {...}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.1 74 8/4/2024
6.0.0 71 8/4/2024
5.0.5 106 5/22/2024
5.0.4 127 2/23/2024
5.0.3 117 2/8/2024
5.0.2 98 2/8/2024
5.0.1 106 2/8/2024
5.0.0 111 1/31/2024
4.0.3 114 1/25/2024
4.0.2 101 1/25/2024
4.0.1 101 1/23/2024
4.0.0 104 1/23/2024
3.0.0 159 1/9/2024
3.0.0-preview1 115 1/8/2024
2.0.1 157 12/29/2023
2.0.0 211 10/16/2023
1.2.1 139 9/18/2023
1.2.0 135 9/17/2023
1.1.1 124 9/15/2023
1.1.0 139 9/15/2023
1.0.0 144 9/13/2023
1.0.0-preview5 126 9/12/2023
1.0.0-preview4 134 9/5/2023
1.0.0-preview3 128 9/3/2023
1.0.0-preview2 121 8/25/2023
1.0.0-preview1 120 8/20/2023