Where is the RestRequest class?
Asked Answered
S

3

19

In the C# tab of the getting started of maingun API, I find the following code.

public static RestResponse SendSimpleMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <[email protected]>");
       request.AddParameter("to", "[email protected]");
       request.AddParameter("to", "[email protected]");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.Method = Method.POST;
       return client.Execute(request);
}

When I google the name of the class, I find several reference to this class in different contexts. However, I can't seem to find the fully qualified name of the RestRequest class anywhere on the mailgun website, google or MSDN to find it's documentation.

Anybody can point out where is this class defined ?

Seriatim answered 24/1, 2013 at 17:52 Comment(2)
you need this library: restsharp.orgWerra
No idea why Mailgun doesn't add this to their own documentation.Leede
V
25

The code looks like it uses RestSharp.

Vaseline answered 24/1, 2013 at 17:55 Comment(1)
Even if the original code doesn't use RestSharp, I suggest converting the code to use it anyway. RestSharp is by far the best rest client library available!Tricia
M
2

RestSharp is available from NuGet. Install it from there.

Magdaleno answered 10/8, 2018 at 21:58 Comment(0)
D
-1

I run in the same issue. But I found out that if you are using JAVA 8 you don't needs any external librairy but just what java provide already here is my code example.

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

public class EmailDAO {

public static Response sendNewPasswordMessage() {
Client client = ClientBuilder.newClient();
client.register(new BasicAuthenticator("api","yourkey"));

WebTarget target = client.target("https://api.mailgun.net/v2/your-domain/messages");

MultivaluedMap formData = new MultivaluedHashMap();
formData.add("from", "Test <[email protected]>");
formData.add("to", "[email protected]");
formData.add("subject", "Hello world");
formData.add("html", "Hello world <br /> <br /> ");

Invocation invocation = target.request().buildPost(Entity.form(formData));
return invocation.invoke();
}

}

Hopes it helps.

Diclinous answered 16/3, 2015 at 2:57 Comment(1)
This is a C#-related question, not Java.Diaconate

© 2022 - 2024 — McMap. All rights reserved.