Skip to content

Instantly share code, notes, and snippets.

@johnsheehan
Created April 29, 2011 04:17
Show Gist options
  • Save johnsheehan/947826 to your computer and use it in GitHub Desktop.
Save johnsheehan/947826 to your computer and use it in GitHub Desktop.
some ideas for the next restsharp
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();
@ayoung
Copy link

ayoung commented Apr 29, 2011

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