Search code examples
c#jsonapirestsharp

how to use restsharp web rest api


hi there i am new to rest api i build these api https://dastanito.ir/test/ex2/api/storiesmaster/read.php https://dastanito.ir/test/ex2/api/storiesmaster/read_one.php?id=60

i used requests lib in python and everything is ok

but i do not know how to use this with restsharp

  var client = new RestClient("https://dastanito.ir/test/ex2/api/storiesmaster/read.php");

            var request = new RestRequest("");

            var response = client.Post(request);
            MessageBox.Show(response.Content.ToString());

Solution

  • Based on RestSharp sample:

    var client = new RestClient("https://dastanito.ir");   
    
    var request = new RestRequest("test/ex2/api/storiesmaster/read.php", Method.GET);
    
    // execute the request
    IRestResponse response = client.Execute(request);
    var content = response.Content; // raw content as string
    

    Output:

    {"StoriesMasters":[{"id":"2","story_code":"002a","master_code":"he3385_1"},{"id":"60","story_code":"001a","master_code":"he3385_1"},{"id":"3","story_code":"c57675","master_code":"ara3433_2"},{"id":"50","story_code":"d8885","master_code":"za76787_3"}]}