Skip to content
myles-mcdonnell edited this page Dec 10, 2012 · 11 revisions

Basic Usage

If you only have a small number of one-off requests to make to an API, you can use RestSharp like so:

var client = new RestClient();
client.BaseUrl = "http://twitter.com";
client.Authenticator = new HttpBasicAuthenticator("username", "password");

var request = new RestRequest();
request.Resource = "statuses/friends_timeline.xml";

IRestResponse response = client.Execute(request);

RestResponse all of the information returned from the remote server. You have access to the headers, content, HTTP status and more. It is recommended that you use the generic version Execute to automatically deserialize the response into .NET classes. See Recommended Usage for an example.

Note about error handling

If there is a network transport error (network is down, failed DNS lookup, etc), RestResponse.Status will be set to ResponseStatus.Error, otherwise it will be ResponseStatus.Completed. If an API returns a 404, ResponseStatus will still be Completed. If you need access to the HTTP status code returned you will find it at RestResponse.StatusCode. The Status property is an indicator of completion independent of the API error handling.

Recommended Usage >>