Skip to content
Newer
Older
100644 70 lines (54 sloc) 2.48 KB
c32b528 @johnsheehan Updated readme
johnsheehan authored
1 # RestSharp - Simple .NET REST Client
a2a034b @johnsheehan added readme
johnsheehan authored
2
c32b528 @johnsheehan Updated readme
johnsheehan authored
3 ### [Official Site/Blog][1] - [@RestSharp][2]
4 ### Please use the [Google Group][3] for feature requests and troubleshooting usage.
5 ### License: Apache License 2.0
a2a034b @johnsheehan added readme
johnsheehan authored
6
c32b528 @johnsheehan Updated readme
johnsheehan authored
7 ### Features
a2a034b @johnsheehan added readme
johnsheehan authored
8
b874d59 @ayoung Update README.markdown
ayoung authored
9 * Supports .NET 3.5+, Silverlight 4, Windows Phone 7, Mono, MonoTouch, Mono for Android
10 * Easy installation using [NuGet](http://nuget.org/packages/RestSharp) for most .NET flavors
a2a034b @johnsheehan added readme
johnsheehan authored
11 * Automatic XML and JSON deserialization
c32b528 @johnsheehan Updated readme
johnsheehan authored
12 * Supports custom serialization and deserialization via ISerializer and IDeserializer
13 * Fuzzy element name matching ('product_id' in XML/JSON will match C# property named 'ProductId')
a2a034b @johnsheehan added readme
johnsheehan authored
14 * Automatic detection of type of content returned
15 * GET, POST, PUT, HEAD, OPTIONS, DELETE supported
7365eec @ayoung Update readme
ayoung authored
16 * Other non-standard HTTP methods also supported
c32b528 @johnsheehan Updated readme
johnsheehan authored
17 * oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators included
18 * Supports custom authentication schemes via IAuthenticator
a2a034b @johnsheehan added readme
johnsheehan authored
19 * Multi-part form/file uploads
20 * T4 Helper to generate C# classes from an XML document
21
2ed3282 @ayoung Specified language for code snippet
ayoung authored
22 ```csharp
23 var client = new RestClient("http://example.com");
24 // client.Authenticator = new HttpBasicAuthenticator(username, password);
9432ff3 @ayoung Added example in readme for aborting async request.
ayoung authored
25
2ed3282 @ayoung Specified language for code snippet
ayoung authored
26 var request = new RestRequest("resource/{id}", Method.POST);
27 request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
28 request.AddUrlSegment("id", 123); // replaces matching token in request.Resource
a2a034b @johnsheehan added readme
johnsheehan authored
29
2ed3282 @ayoung Specified language for code snippet
ayoung authored
30 // add parameters for all properties on an object
31 request.AddObject(object);
a2a034b @johnsheehan added readme
johnsheehan authored
32
2ed3282 @ayoung Specified language for code snippet
ayoung authored
33 // or just whitelisted properties
34 request.AddObject(object, "PersonId", "Name", ...);
9432ff3 @ayoung Added example in readme for aborting async request.
ayoung authored
35
2ed3282 @ayoung Specified language for code snippet
ayoung authored
36 // easily add HTTP Headers
37 request.AddHeader("header", "value");
a2a034b @johnsheehan added readme
johnsheehan authored
38
2ed3282 @ayoung Specified language for code snippet
ayoung authored
39 // add files to upload (works with compatible verbs)
40 request.AddFile(path);
9432ff3 @ayoung Added example in readme for aborting async request.
ayoung authored
41
2ed3282 @ayoung Specified language for code snippet
ayoung authored
42 // execute the request
43 RestResponse response = client.Execute(request);
44 var content = response.Content; // raw content as string
9432ff3 @ayoung Added example in readme for aborting async request.
ayoung authored
45
2ed3282 @ayoung Specified language for code snippet
ayoung authored
46 // or automatically deserialize result
47 // return content type is sniffed but can be explicitly set via RestClient.AddHandler();
48 RestResponse<Person> response2 = client.Execute<Person>(request);
49 var name = response2.Data.Name;
a2a034b @johnsheehan added readme
johnsheehan authored
50
2ed3282 @ayoung Specified language for code snippet
ayoung authored
51 // or download and save file to disk
52 client.DownloadData(request).SaveAs(path);
560cf02 @johnsheehan updated README to reflect recent changes
johnsheehan authored
53
2ed3282 @ayoung Specified language for code snippet
ayoung authored
54 // easy async support
55 client.ExecuteAsync(request, response => {
56 Console.WriteLine(response.Content);
57 });
c32b528 @johnsheehan Updated readme
johnsheehan authored
58
2ed3282 @ayoung Specified language for code snippet
ayoung authored
59 // async with deserialization
60 var asyncHandle = client.ExecuteAsync<Person>(request, response => {
61 Console.WriteLine(response.Data.Name);
62 });
63
64 // abort the request on demand
65 asyncHandle.Abort();
66 ```
a2a034b @johnsheehan added readme
johnsheehan authored
67
68 [1]: http://restsharp.org
c32b528 @johnsheehan Updated readme
johnsheehan authored
69 [2]: http://twitter.com/RestSharp
70 [3]: http://groups.google.com/group/RestSharp
Something went wrong with that request. Please try again.