Introduction
Because nancy does not seem to support named url parameters but only url segments and easyhttp makes it’s urls with named parameters only, I decided to add this feature to easyhttp.
Url with named parameters
Url with segments
How it works
You used to be able to do this.
csharp
var http = new HttpClient();
http.Request.Accept = HttpContentTypes.ApplicationJson;
var result = http.Get("http://localhost/trees", new {Id = 1} );
Which resulted in easyhttp creating a url for you that looked like this.
From version 1.6.30.0 onwards you can do this.
csharp
var http = new HttpClient();
http.Request.Accept = HttpContentTypes.ApplicationJson;
http.Request.ParametersAsSegments = true;
var result = http.Get("http://localhost/trees", new {Id = 1});
Note that the line http.Request.ParametersAsSegments is now true. That property is false by default, as one would expect from a boolean.
Which will result in a url looking like this.
Note that the order of the propertie in the object you are passing is important.
csharp
var result = http.Get("http://localhost/trees", new {Id = 1, Name = "test"});
Will result in.
While
csharp
var result = http.Get("http://localhost/trees", new {Name = "test", Id = 1});
Will result in.
Conclusion
Thanks to Hadi for letting me do this.
PS: I added a whole lot of documentation to easyhttp in the github wiki.
PS2: And I want to also note that I don’t like markdown.
PS3: And that all the code in this post is C#.