Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a7b0/uri-templates
.NET implementation of URI template spec (RFC6570)
https://github.com/a7b0/uri-templates
dotnet rfc-6570 uri-template
Last synced: 18 days ago
JSON representation
.NET implementation of URI template spec (RFC6570)
- Host: GitHub
- URL: https://github.com/a7b0/uri-templates
- Owner: a7b0
- License: mit
- Created: 2013-12-14T18:01:44.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T09:00:41.000Z (almost 2 years ago)
- Last Synced: 2024-09-18T09:03:53.573Z (about 2 months ago)
- Topics: dotnet, rfc-6570, uri-template
- Language: C#
- Size: 64.5 KB
- Stars: 16
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Resta.UriTemplates
==================[![Build Status](https://cloud.drone.io/api/badges/a7b0/uri-templates/status.svg)](https://cloud.drone.io/a7b0/uri-templates)
[![NuGet](http://img.shields.io/nuget/v/Resta.UriTemplates.svg)](https://www.nuget.org/packages/Resta.UriTemplates/).NET implementation of the URI template spec ([RFC6570](http://tools.ietf.org/html/rfc6570)):
* Supports up to level 4 template expressions
* Fluent API for manipulating URI templates
* Strong validation and error reporting
* Precompiled URI templates
* Partial resolve of URI templates
* It is passes all tests defined by the [uritemplate-test](https://github.com/uri-templates/uritemplate-test) suite.
* Targets .NET Standard 2.0Install
-------Install via [NuGet package](https://www.nuget.org/packages/Resta.UriTemplates)
Examples
--------Resolve a URI template:
```csharp
var template = new UriTemplate("http://example.org/{area}/news{?type,count}");
var uri = template.Resolve(new Dictionary
{
{ "area", "world" },
{ "type", "actual" },
{ "count", "10" }
});
Assert.AreEqual("http://example.org/world/news?type=actual&count=10", uri);
```Resolve a URI template using fluent interface:
```csharp
var template = new UriTemplate("http://example.org/{area}/news{?type}");var uri = template.GetResolver()
.Bind("area", "world")
.Bind("type", new string[] { "it", "music", "art" } )
.Resolve();Assert.AreEqual("http://example.org/world/news?type=it,music,art", uri);
```Construct a URI template:
```csharp
var template = new UriTemplateBuilder()
.Literal("http://example.org/")
.Simple(new VarSpec("area"))
.Literal("/last-news")
.Query("type", new VarSpec("count"))
.Build();Assert.AreEqual("http://example.org/{area}/news{?type,count}", template.ToString());
```Partial resolve a URI template:
```csharp
var template = new UriTemplate("http://example.org/{area}/news{?type,count}");
var partiallyResolved = template.GetResolver().Bind("count", "10").ResolveTemplate();Assert.AreEqual("http://example.org/{area}/news?count=10{&type}", partiallyResolved.ToString());
```**NB!** Partial resolve of expressions `default`, `reserved` and `fragment` is not possible for multiple variables.
License
-------Copyright 2013 Pavel Shkarin
[MIT License](http://mit-license.org/)