Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# documentation is not up to date with regard to RestSharp #576

Open
Reeceeboii opened this issue Feb 2, 2022 · 1 comment
Open

C# documentation is not up to date with regard to RestSharp #576

Reeceeboii opened this issue Feb 2, 2022 · 1 comment

Comments

@Reeceeboii
Copy link

Reeceeboii commented Feb 2, 2022

The C# documentation is using an old version of RestSharp, and the code given in examples will not function for the current stable NuGet install.

From https://restsharp.dev/v107/#restsharp-v107:

The latest version of RestSharp is v107. It's a major upgrade, which contains quite a few breaking changes.

The most important change is that RestSharp stop using the legacy HttpWebRequest class, and uses well-known 'HttpClient' instead. This move solves lots of issues, like hanging connections due to improper HttpClient instance cache, updated protocols support, and many other problems.

Another big change is that SimpleJson is retired completely from the code base. Instead, RestSharp uses JsonSerializer from the System.Text.Json package, which is the default serializer for ASP.NET Core.

Finally, most of the interfaces are now gone.

MailGun Docs (link):

image

Using code with RestSharp latest stable via NuGet (link):

image

Updated code for v107:

using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Threading.Tasks;

public class SendSimpleMessageChunk
{

    public static void Main(string[] args)
    {
        Console.WriteLine(SendSimpleMessage().Result.Content);

        Console.ReadLine();
    }

    public async static Task<RestResponse> SendSimpleMessage()
    {
        RestClientOptions options = new RestClientOptions(new Uri("https://api.mailgun.net/v3"));
        RestClient client = new RestClient(options);
        
        client.Authenticator =
            new HttpBasicAuthenticator("api",
                "YOUR_API_KEY");

        RestRequest request = new RestRequest();
        request.AddParameter("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.Resource = "{domain}/messages";
        request.AddParameter("from", "Excited User <mailgun@YOUR_DOMAIN_NAME>");
        request.AddParameter("to", "[email protected]");
        request.AddParameter("to", "YOU@YOUR_DOMAIN_NAME");
        request.AddParameter("subject", "Hello");
        request.AddParameter("text", "Testing some Mailgun awesomness!");
        request.Method = Method.Post;

        return await client.ExecuteAsync(request);
    }

}
@warrenkc
Copy link
Contributor

I hope this gets updated soon. It has been months....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants