[{"data":1,"prerenderedAt":70},["Reactive",2],{"/samples/csharp/restsharp":3,"related:xM59CYFoof":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/samples/csharp/restsharp","csharp",false,"","Restsharp","RestSharp is a popular third-party library that simplifies making HTTP requests and handling responses in .NET applications. It provides an intuitive and easy-to-use API for interacting with RESTful web services, enabling developers to perform common HTTP operations such as GET, POST, PUT, DELETE, and more. RestSharp abstracts away the complexities of HTTP communication, streamlining the process of consuming web APIs and processing their responses.","CSharp","RestSharp","https://restsharp.dev/",{"type":14,"children":15,"toc":52},"root",[16,31,43],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,29],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":11},"text",{"type":28,"value":30}," is a popular third-party library that simplifies making HTTP requests and handling responses in .NET applications. It provides an intuitive and easy-to-use API for interacting with RESTful web services, enabling developers to perform common HTTP operations such as GET, POST, PUT, DELETE, and more. RestSharp abstracts away the complexities of HTTP communication, streamlining the process of consuming web APIs and processing their responses.",{"type":17,"tag":32,"props":33,"children":37},"pre",{"className":34,"code":36,"language":5,"meta":7},[35],"language-csharp","using RestSharp;\nusing System;\nusing System.IO;\nusing Newtonsoft.Json;\nusing RestSharp.Authenticators;\n\npublic class Conversion\n{\n    private RestClient Client;\n    string api_key = \"sk_XXXXXXXXXXXXXX\";\n\n    public Conversion(string api_key, string endpoint = \"pdf\") \n    {\n        if (! (new[] {\"pdf\", \"png\", \"jpg\", \"webp\"}.Contains(endpoint))) \n        {\n            throw new ArgumentException(\"Invalid endpoint\");\n        }\n\n        Client = new RestClient(\"https://api.pdfshift.io/v3/convert/\" + endpoint)\n        this.api_key = api_key;\n    }\n\n    public byte[] Convert(dynamic parameters) \n    {\n        RestRequest Request = new RestRequest(Method.POST);\n        Request.AddHeader(\"X-API-Key\", this.api_key);\n        Request.AddJsonBody(parameters);\n        var response = Client.Execute(Request);\n\n        if(response.IsSuccessful)\n        {\n            if (parameters.ContainsKey(\"filename\") || parameters.ContainsKey(\"webhook\")) \n            {\n                return System.Text.Encoding.Default.GetBytes(response.Content);\n            }\n            return response.RawBytes;\n        }\n        else\n        {\n            throw new Exception(response.ErrorMessage);\n        }\n    }\n}\n",[38],{"type":17,"tag":39,"props":40,"children":41},"code",{"__ignoreMap":7},[42],{"type":28,"value":36},{"type":17,"tag":32,"props":44,"children":47},{"className":45,"code":46,"language":5,"meta":7},[35],"Conversion conversion = new Conversion(\"sk_XXXXXXXXXXXXXX\");\nvar json = new {\n    source = \"https://en.wikipedia.org/wiki/REST\"\n}\n\nbyte[] response = conversion.Convert(parameters);\nFile.WriteAllBytes(\"result.pdf\", response);\n",[48],{"type":17,"tag":39,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":28,"value":46},{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:samples:csharp:restsharp.md","content","samples/csharp/restsharp.md","md",[61,65,69],{"_path":62,"language":10,"library":63,"_id":64},"/samples/csharp/httpclient","HttpClient","content:samples:csharp:httpclient.md",{"_path":66,"language":10,"library":67,"_id":68},"/samples/csharp/httpwebrequest","HttpWebRequest","content:samples:csharp:httpwebrequest.md",{"_path":4,"language":10,"library":11,"_id":56},1785426823630]