Skip to content

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

Open
@Reeceeboii

Description

@Reeceeboii

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);
    }

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions