Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jchristn/urlmatcher
Simple URL matcher library allowing you to match based on explicit string or parameters
https://github.com/jchristn/urlmatcher
csharp dotnet dotnet-core match nuget url
Last synced: 21 days ago
JSON representation
Simple URL matcher library allowing you to match based on explicit string or parameters
- Host: GitHub
- URL: https://github.com/jchristn/urlmatcher
- Owner: jchristn
- License: mit
- Created: 2021-02-22T16:41:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T15:37:10.000Z (5 months ago)
- Last Synced: 2024-12-07T19:25:05.412Z (26 days ago)
- Topics: csharp, dotnet, dotnet-core, match, nuget, url
- Language: C#
- Homepage:
- Size: 818 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![alt tag](https://github.com/jchristn/urlmatcher/blob/main/assets/icon.ico)
# UrlMatcher
[![NuGet Version](https://img.shields.io/nuget/v/UrlMatcher.svg?style=flat)](https://www.nuget.org/packages/UrlMatcher/) [![NuGet](https://img.shields.io/nuget/dt/UrlMatcher.svg)](https://www.nuget.org/packages/UrlMatcher)
Simple URL matcher library allowing you to match based on explicit string or parameters, targeted to .NET Core, .NET Standard, and .NET Framework.
## Help or Feedback
First things first - do you need help or have feedback? File an issue here! We'd love to hear from you.
## New in v3.0.0
- Refactor to support both static methods and instances
- Instances take either a `Uri` or `string` (URL)## It's Really Easy... I Mean, REALLY Easy
Refer to the ```Test``` project for a working example.
### Simple Static Method
Use the static method when you need to compare an input URL against a pattern once.
```csharp
using UrlMatcher;string pattern = "/{version}/users/{userId}";
NameValueCollection vals = null;if (Matcher.Match("/v1.0/users/42", pattern, out vals))
{
Console.WriteLine("Match!");
Console.WriteLine(" version : " + vals["version"]); // v1.0
Console.WriteLine(" userId : " + vals["userId"]); // 42
}
else
{
Console.WriteLine("No match");
}
```### Instance Method
Instantiate the class by supplying the URI or URL. Using the instance method eliminates the need to repeatedly parse the input URI or URL.
```csharp
using UrlMatcher;Matcher matcher = new Matcher("/v1.0/users/42");
NameValueCollection vals = null;if (matcher.Match("/{version}/users/{userId}")) // do something
else if (matcher.Match("/{version}/hobbies/{hobbyId}")) // do something
else
{
Console.WriteLine("No match");
}
```## Version History
Please refer to CHANGELOG.md.