You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/usage.md
+28
Original file line number
Diff line number
Diff line change
@@ -360,6 +360,34 @@ var statusCode = client.PostJsonAsync("orders", request, cancellationToken);
360
360
361
361
The same two extensions also exist for `PUT` requests (`PutJsonAsync`);
362
362
363
+
### JSON streaming APIs
364
+
365
+
For HTTP API endpoints that stream the response data (like [Twitter search stream](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream)) you can use RestSharp with `StreamJsonAsync<T>`, which returns an `IAsyncEnumerable<T>`:
The main limitation of this function is that it expects each JSON object to be returned as a single line. It is unable to parse the response by combining multiple lines into a JSON string.
382
+
383
+
### Downloading binary data
384
+
385
+
There are two functions that allow you to download binary data from the remote API.
386
+
387
+
First, there's `DownloadDataAsync`, which returns `Task<byte[]`. It will read the binary response to the end, and return the whole binary content as a byte array. It works well for downloading smaller files.
388
+
389
+
For larger responses, you can use `DownloadStreamAsync` that returns `Task<Stream>`. This function allows you to open a stream reader and asynchronously stream large responses to memory or disk.
390
+
363
391
## Blazor support
364
392
365
393
Inside a Blazor webassembly app, you can make requests to external API endpoints. Microsoft examples show how to do it with `HttpClient`, and it's also possible to use RestSharp for the same purpose.
0 commit comments