Skip to content
Simple REST and HTTP API Client for .NET http://restsharp.org
C#
Find file
Pull request Compare This branch is 599 commits behind restsharp:master.
Latest commit 1e8f8fa @attilah Removed unused NewtonsoftJsonMonoTouch.dll and Newtonsoft.Json.MonoDr…
…oid.dll binaries.

MonoDroid and MonoTouch project file list is synced with the desktop project's file list.
AssemblyInfo.cs file added to MonoTouch and MonoDroid projects.
Newtonsoft.Json reference updated to the latest 4.5.5 release for the test project in the NuGet packages.config file.
RestSharp.Android output assembly name modified to RestSharp.MonoDroid to be conform.
Double nesting of Authenticators folders in MonoTouch and MonoDroid has been fixed.
Removed accidental NewFolder1 from Silverlight project.
Failed to load latest commit information.
.nuget Removing packages folder. NuGet will regenerate on first build.
RestSharp.IntegrationTests Removing packages folder. NuGet will regenerate on first build.
RestSharp.MonoDroid Removed unused NewtonsoftJsonMonoTouch.dll and Newtonsoft.Json.MonoDr…
RestSharp.MonoTouch Removed unused NewtonsoftJsonMonoTouch.dll and Newtonsoft.Json.MonoDr…
RestSharp.Net4 Added some missing OAuth files to the .NET4 and Silverlight projects
RestSharp.Silverlight Removed unused NewtonsoftJsonMonoTouch.dll and Newtonsoft.Json.MonoDr…
RestSharp.Tests Removed unused NewtonsoftJsonMonoTouch.dll and Newtonsoft.Json.MonoDr…
RestSharp.WindowsPhone.Mango NuGet modified the Mango proj
RestSharp.WindowsPhone Removing packages folder. NuGet will regenerate on first build.
RestSharp Added some missing OAuth files to the .NET4 and Silverlight projects
Tools nuget 1.7
.gitignore Removing packages folder. NuGet will regenerate on first build.
LICENSE.txt Added license
README.markdown Specified language for code snippet
RestSharp.Mono.sln Mono solution and misc clean up
RestSharp.sln Removing packages folder. NuGet will regenerate on first build.
package.cmd 103.1 changes (.net 4 dynamic and fixed invalidcastexception
readme.txt For @xpaulbettsx
restsharp.nuspec Updated .nuspec release notes

README.markdown

RestSharp - Simple .NET REST Client

Official Site/Blog - @RestSharp

Please use the Google Group for feature requests and troubleshooting usage.

License: Apache License 2.0

Features

  • Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch
  • Automatic XML and JSON deserialization
  • Supports custom serialization and deserialization via ISerializer and IDeserializer
  • Fuzzy element name matching ('product_id' in XML/JSON will match C# property named 'ProductId')
  • Automatic detection of type of content returned
  • GET, POST, PUT, HEAD, OPTIONS, DELETE supported
  • oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators included
  • Supports custom authentication schemes via IAuthenticator
  • Multi-part form/file uploads
  • T4 Helper to generate C# classes from an XML document
var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", 123); // replaces matching token in request.Resource

// add parameters for all properties on an object
request.AddObject(object);

// or just whitelisted properties
request.AddObject(object, "PersonId", "Name", ...);

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
RestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person> response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

// or download and save file to disk
client.DownloadData(request).SaveAs(path);

// easy async support
client.ExecuteAsync(request, response => {
    Console.WriteLine(response.Content);
});

// async with deserialization
var asyncHandle = client.ExecuteAsync<Person>(request, response => {
    Console.WriteLine(response.Data.Name);
});

// abort the request on demand
asyncHandle.Abort();
Something went wrong with that request. Please try again.