Skip to content

RestSharp

Mahmoud A. Zaid edited this page Mar 12, 2019 · 1 revision

What is RestSharp?

  • RestSharp is a comprehensive, open-source HTTP client library that works with all kinds of DotNet technologies. It can be used to build robust applications by making it easy to interface with public APIs and quickly access data without the complexity of dealing with raw HTTP requests. RestSharp combines myriad advantages and time-saving features with a simple, clean interface, making it one of the hottest REST tools being used today.

RestSharp Features

  • Custom serialization and deserialization via ISerializer and IDeserializer.
  • Both synchronous and asynchronous requests.
  • Automatic XML and JSON parsing, including fuzzy element name matching (“product_id” in XML/JSON will match C# property named ‘ProductId’).
  • Multipart file/form uploads.
  • oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authentication.
  • Support for features such as GET, PUT, HEAD, POST, DELETE and OPTIONS.

Handling Requests

  • Using RestRequest creates a new request to a specified URL.
  • AddParameter will add a new parameter to the request.
  • HTTP headers can easily be added to the request you have generated, using request.AddHeader.
  • You can replace a token in the request, by using request.AddUrlSegment. This will replace the matching token in the request.
  • To execute the request, the command client.Execute(request) is used. The response object can also be used to parse your data.

Authenticators

RestSharp supports the following Authenticators:

  • HttpBasicAuthenticator
  • IAuthenticator
  • NtlmAuthenticator
  • OAuth1Authenticator
  • OAuth2Authenticator
  • SimpleAuthenticator
Clone this wiki locally