Created
April 29, 2011 04:17
-
-
Save johnsheehan/947826 to your computer and use it in GitHub Desktop.
some ideas for the next restsharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = new Http("https://api.twilio.com/{version}/Accounts"); | |
http.AddUrlSegment("version", "2010-04-01"); | |
http.AddParameter("name", "value"); | |
http.Authenticate = (request) => // authenticators would just follow this contract | |
{ | |
request.AddHeader("name", "value"); | |
}; | |
http.Complete = (response, data) => | |
{ | |
// data is dynamic | |
// if response content type matches registered handler, it deserializes | |
// otherwise it's just the response body as string | |
}; | |
// for any exception except WebException | |
http.Error = (error) => | |
{ | |
// handle error | |
}; | |
http.Post(); |
Segments, Params and Headers wouldn't work well as dynamics because the names for these do not match the naming rules for C# properties.
opt.Headers.Accept-Charset = "utf-8"; // not valid C#
I like the first version of the constructor. Its a more familiar pattern of string formatting, less typing, and less effort to implement -- although RestSharp already does something similar to the latter.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was also thinking of maybe doing URL segments all in the constructor:
or