Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a REST Get-Request in C#?

Tags:

rest

c#

curl

get

I am new to C# and still try to get familiar with its environment.

I'd like to make a REST-Request in Get-Mode. The guys who gave me the API-Access provided me with following information:

HTTP Methods: GET
Authentication: None
Formats: xml
Parameters: format, apikey [GET], lang [GET], q [GET]
CURL Example: curl --get --data lang="de" --data q="query" --data apikey="QWERTY123456" http://jokr.info/api/v8/search/item.xml

And I don't know how to put this in C#. I tried to use WebClient but I do not know how to put my request with the parameters in action.

like image 252
Clue Avatar asked Dec 04 '25 12:12

Clue


1 Answers

There is a popular library RestSharp.

Here is an exemple :

var client = new RestClient("http://example.com");
var request = new RestRequest("api");
request.AddParameter("foo", "bar");

client.ExecuteAsync(request, response => {
    // do something with the response
});

Which translates to http://example.com/api?foo=bar

like image 110
Cybermaxs Avatar answered Dec 06 '25 04:12

Cybermaxs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!