Search code examples
c#getpostmanrestsharp

RestSharp unable to identify GET Method


I am trying to use Rest Sharp for the first time for automating API Testing. I started with sending a basic GET call but Rest Sharp does not recognize the GET method. I have already added RESTSHARP NuGet package. Any idea what am I doing wrong? Any link to existing API testing code/framework?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;

namespace Postman
{
    class Program
    {
       public static void Main(string[] args)
        {
                var client = new RestClient("");
                client.Timeout = 500;
                var request = new RestRequest(Method.GET);
                request.AddParameter("", "");
                request.AddParameter("", "");
                request.AddParameter("", "");
                IRestResponse response = client.Execute(request);
                Console.WriteLine(response.Content);
            
        }
    }
    
}

(url in the code hidden for confidentiality)

Check screenshot here code Updated


Solution

  • You most certainly downloaded the most recent major version of RestSharp package from NuGet, v. 107. There are many breaking changes in that version, and your code will not work with it.

    If you need to get this done quick, downgrade the package version to 106.15.0, and the errors you see should disappear. Otherwise, you can try to follow the migration guide from the linked documentation.