Need help with FluentUriBuilder?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

129 Stars 10 Forks MIT License 40 Commits 1 Opened issues


A safer and more readable way to build URI's in .NET

Services available


Need anything else?

Contributors list

# 276,950
40 commits


A safer and more readable way to build URI's in .NET

Build status NuGet package

Quick example

To build this new URI:

ftp://user:[email protected]:888/path/to/file?param1=val1&param2=a%23value%26with%40weird%3fcharacters#fragment


var uri = FluentUriBuilder.Create()
    .Credentials("user", "password")
    .QueryParams(new {
        param1 = "val1",
        param2 = "a#value&[email protected]?characters"


You often see code that creates URI's using simple string concatenation or format strings:

var valueWithWeirdCharacters = "a#value&[email protected]?characters";
var badUri1 = "" + valueWithWeirdCharacters + "&param2=asdf";
var badUri2 = string.Format("{0}&param2=asdf", valueWithWeirdCharacters);

The result is an invalid URI because the value of

is not escaped:
"[email protected]?characters&param2=asdf"

One alternative is to escape each value using

var correctUri = "" +
    Uri.EscapeDataString(valueWithWeirdCharacters) +

But this quickly gets ugly when you have a lot of arguments, and it is easy to forget.


var valueWithWeirdCharacters = "a#value&[email protected]?characters";
var uriBuilder = new UriBuilder("");
var parameters = HttpUtility.ParseQueryString(string.Empty);

parameters["param1"] = valueWithWeirdCharacters; parameters["param2"] = "asdf";

uriBuilder.Query = parameters.ToString();

var correctUri = uriBuilder.AbsoluteUri;

This is correct, but also the most complicated and unreadable of all of the above examples. This is why I created

: to allow creating URI's in a safe and readable way:
var valueWithWeirdCharacters = "a#value&[email protected]?characters";
var uri = FluentUriBuilder
    .QueryParam("param1", valueWithWeirdCharacters)
    .QueryParam("param2", "asdf")

More Examples

Query parameters can also be specified using an

var params = new Dictionary {
    { "user", "averagejoe236" },
    { "apiKey", "af43af43rcfaf34xqf" }

var uri = FluentUriBuilder.Create() .Scheme(UriScheme.Http) .Host("") .Path("posts") .QueryParams(params) .ToString();

Or one by one, by calling

.QueryParam("key", "value")
var uri = FluentUriBuilder.Create()
    .QueryParam("q", "FluentUriBuilder")
    .QueryParam("source", "hp")

The latter can be used to specify more query parameters with the same name.

To modify an existing URI:

var uri = FluentUriBuilder.From("")

This example returns a

instance instead of a string because of the
call at the end.

Framework Support

The project currently supports .NET 2.0+. .NET Core support is planned.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.