0

I'm working on a C# console application which calls external REST APIs with RestSharp.

The issue now is that I have to access an API that only allows a custom request method like FOOBAR instead of the traditional GET or POST.

using RestSharp;

var request = new RestRequest();
request.Method = Method.POST;

Unfortunately, I haven't seen anything pertaining to custom request methods in RestSharp's docs or GitHub issues section.

Keep in mind that I only have a basic knowledge on this, so my trials might be considered silly.

I've tried assigning a string to it but it only accepts an enum.

request.Method = "FOOBAR"; // Does not accept strings

I've also tried converting a string to enum using code from this answer, but this defaults to a GET. It might be like that due to my converted string not being in their enum Method.

Enum.TryParse("FOOBAR", out Method customRequestMethod);
request.Method = customRequestMethod; // Defaults to GET

If this is not possible with RestSharp, is this feature doable with HttpClient or Flurl?

seanquijote
  • 150
  • 1
  • 3
  • 12
  • 1
    You should not call that a feature but a misuse. Something with REST in its name should not allow things that aren't anywhere near REST behaviour. HttpClient should allow such a call. You need to use then the SendAsync methods that allow a custom HttpRequestMessage that allow a custom HttpMethod. – Ralf Nov 20 '20 at 11:00
  • @Ralf alright thank you for the clarification. Will proceed to do more research on HttpClient. – seanquijote Nov 20 '20 at 11:38

0 Answers0