Skip to content

Commit c646c6f

Browse files
committed
Added a small async example
1 parent b48aee4 commit c646c6f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/getting-started/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,29 @@ You have access to the headers, content, HTTP status and more.
2727

2828
It is recommended that you use the generic overloads like `Get<T>` to automatically deserialize the response into .NET classes.
2929

30-
## Note about error handling
30+
## Asynchronous Calls
31+
32+
All synchronous methods have their asynchronous siblings, suffixed with `Async`.
33+
34+
So, instead of `Get<T>` that returns `T` or `Execute<T>`, which returns `IRestResponse<T>`,
35+
you can use `GetAsync<T>` and `ExecuteAsync<T>`. The arguments set is usually identical.
36+
You can optionally supply the cancellation token, which by default is set to `CancellationToken.None`.
37+
38+
For example:
39+
40+
```csharp
41+
using RestSharp;
42+
using RestSharp.Authenticators;
43+
44+
var client = new RestClient("https://api.twitter.com/1.1");
45+
client.Authenticator = new HttpBasicAuthenticator("username", "password");
46+
47+
var request = new RestRequest("statuses/home_timeline.json", DataFormat.Json);
48+
49+
var timeline = await client.Get<HomeTimeline>(request, cancellationToken);
50+
```
51+
52+
## Note About Error Handling
3153

3254
Normally, RestSharp doesn't throw an exception if the request fails.
3355

0 commit comments

Comments
 (0)