Questions tagged [restsharp]

RestSharp is a simple to use REST client library for .NET

RestSharp takes the pain out of calling REST services from .NET. This library takes care of the quirks in .NET's HTTP classes, handles deserialization cleanly, simplifies making asynchronous calls, and just makes it really easy to implement calls to REST services from inside your application.

RestSharp comes with a built-in JSON serializer. The default serializer has been compatible with the Json.NET project but this compatibility has been given up since release 100.3.

Installation Installing RestSharp can most easily be done using its NuGet package:

Install-Package RestSharp

Resources

2486 questions
19
votes
5 answers

RestSharp Deserialization with JSON Array

I have a JSON response that I'm trying to deserialize with RestSharp, and it looks like this: {"devices":[{"device":{"id":7,"deviceid":"abc123","name":"Name"}}, {"device":{"id":1,"deviceid":"def456","name":"Name"}}], "total":2, …
Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44
19
votes
4 answers

Example of RestSharp ASYNC client.ExecuteAsync () works

Could someone please help me modify the code below: client.ExecuteAsync(request, response => { Console.WriteLine(response.Content); }); Basically I want to use ExecuteAsync method above but don't want to print but return response.Content to the…
Nil Pun
  • 17,035
  • 39
  • 172
  • 294
18
votes
3 answers

How to mock RestSharp portable library in Unit Test

I would like to mockup the RestClient class for test purposes public class DataServices : IDataServices { private readonly IRestClient _restClient; public DataServices(IRestClient restClient) { _restClient = restClient; } …
Florian SANTI
  • 531
  • 1
  • 5
  • 13
18
votes
3 answers

How to add json to RestSharp POST request

I have the following JSON string that is passed into my c# code as a string parameter - AddLocation(string…
ihatemash
  • 1,474
  • 3
  • 21
  • 42
18
votes
4 answers

Get value from RestSharp response headers

I'm hoping someone can help with an issue I'm having with RestSharp. It's all working; I'm getting my reply using the following code: var client = new RestClient("http://mybaseuri.com"); var request = new RestRequest("service/{id}",…
user3580862
  • 183
  • 1
  • 1
  • 4
18
votes
4 answers

Get JSON response using RestSharp

I'm new to C# and I'm trying to get the JSON response from a REST request using RestSharp; The request I want to execute is the following one : "http://myurl.com/api/getCatalog?token=saga001". It works great if I'm executing it in a browser. I've…
Adrien Budet
  • 327
  • 2
  • 3
  • 13
18
votes
6 answers

Web Request through Proxy using RestSharp

I'm trying to make a webrequest through a proxy on Windows phone 7. From what I can see the Compact Framework does not include the configuring of a proxy for the HttpWebRequest object. I tried using RestSharp but the RestClient also does not allow…
Flaviu Zapca
  • 181
  • 1
  • 1
  • 4
17
votes
6 answers

RestSharp serialization to JSON, object is not using SerializeAs attribute as expected

I am using RestSharp (version 104.4 via NuGet) to make calls to a Rest Web Service. I have designed a set of objects (POCO) which matches resources exposed in the API. However, my objects property names does not match those expected by the Rest…
MaxiWheat
  • 6,133
  • 6
  • 47
  • 76
16
votes
2 answers

Does RestSharp overwrite manually set Content-Type?

I'm creating a RestSharp.RestRequest via: RestRequest request = new RestRequest(); request.Method = Method.POST; request.Resource = "/rest-uri"; request.AddHeader("Content-Type", "application/someContentType"); string xml = "
DIF
  • 2,470
  • 6
  • 35
  • 49
16
votes
3 answers

RestSharp with JWT-authentication doesn't work

This is the page where I "learned" how to do it: https://stormpath.com/blog/token-authentication-asp-net-core But for me this is not working (doesn't work with Fiddler, too) There is this controller for my ApplicationUser-model: [Authorize] //works…
Matthias Burger
  • 5,549
  • 7
  • 49
  • 94
16
votes
1 answer

How to RestSharp add client certificate in Https request? (C#)

How to RestSharp add client certificate in Https request ? My code it doesn't work . public static IRestResponse AsyncHttpRequestLogIn(string path, string method, object obj) { var client = new RestClient(Constants.BASE_URL +…
Rabbit
  • 161
  • 1
  • 1
  • 5
16
votes
3 answers

What is a proper strategy for handling error responses from RestSharp?

A typical http call using RestSharp looks as follows: var client = new RestClient("http://exampleapi.com"); var request = new RestRequest("someapi", Method.GET); IRestResponse response = client.Execute(request); From the documentation at…
Robert
  • 353
  • 3
  • 14
16
votes
1 answer

401 when calling Web Service only on particular machines

We have developed a WPF Application with C# and are using RestSharp to communicate with a simple Web Service like this: Client = new RestClient(serviceUri.AbsoluteUri); Client.Authenticator = new NtlmAuthenticator(SvcUserName,…
hoetz
  • 2,368
  • 4
  • 26
  • 58
16
votes
1 answer

How can I catch exceptions with RestSharp

I am working on a project with RestSharp. Over time I discovered several exceptions that RestResponse class can throw, most of which I have to handle so my app doesn't crash. How can I know of all possible exceptions and handle them individually.
okeziestanley
  • 329
  • 1
  • 4
  • 9
16
votes
1 answer

When consuming RESTful APIs, when do you recommend using RestSharp and when HttpClient?

I've been searching for this answer for some time but had no success. I've always used RestSharp and I find it pretty neat, but then realized that there's the HttpClient provided by Microsoft and it looks to cover same functionality at first…
Pablo CG
  • 818
  • 6
  • 18