2017-07-05 17:42:13 -04:00
2017-07-05 17:33:55 -04:00
2016-11-08 21:59:33 -05:00
2017-07-05 17:39:27 -04:00
2017-07-05 17:37:03 -04:00
2016-11-08 22:17:29 -05:00
2017-07-05 16:37:42 -04:00

UriBuilder.Fluent

Coverage Status Build status

This places extension methods over System.UriBuilder to help deal with query string parameters, and create more of a fluent interface. Unlike other projects, this NetStandardLibrary compliant package builds ontop of trusty UriBuilder, does not use custom Uri generators, or have outside dependencies. Unit tests continue to be a first class citizen!

Getting started

Just install the nuget package install-package UriBuilder.Fluent and thats it. The extension methods should be available to you!

Code Example

This lets you do things like


new UriBuilder()
         .WithParameter("awesome", "yodawg")
         .WithParameter("fun", ["cool", "yay"])
         .WithHost("awesome.com")
         .WithPathSegment("seg")
         .UseHttps()
         .ToString()

result: https://awesome.com/seg?awesome=yodawg&fun=cool,yay

or


new UriBuilder("https://awesome.com/yo)
    .WithParameter("id", "5")
    .ToString();

result: https://awesome.com/yo?id=5

you can even pass a dictionary of parameters


var dictionary = new Dictionary<string, string>()
{
    ["yo"] = "dawg"
};

new UriBuilder("http://awesome.com")
        .WithParameter(dictionary);

result: http://awesome.com/?yo=dawg

ToEscapeString() vs. ToEscapeDataString()

There are two extension methods for performing Uri encoding.

ToEscapeString()

Performs encoding only on the Uri query string and returns the Uri as a string.


var uri = new UriBuilder("https://awesome.com")
    .WithParameter("yo", "dawg<")
    .ToEscapeString();

result: http://awesome.com/?yo=dawg%3C

ToEscapeDataString()

Performs encoding on the whole Uri and returns the Uri as a string.


var uri = new UriBuilder("https://awesome.com")
    .WithParameter("yo", "dawg<")
    .ToEscapeDataString();

result: http%3A%2F%2Fawesome.com%2F%3Fyo%3Ddawg%3C

Description
A set of fluent extensions ontop of System.UriBuilder
Readme MIT 190 KiB
Languages
C# 96.5%
Makefile 3.5%