I'd like to make a call to Mailgun service with Play's WS api. Mailgun requires a API key sent for Authentication, and per their 'jersey' client example, they specify this API key as 'HTTPBasicAuthFilter' with the client, as below:
public static ClientResponse SendSimpleMessage() {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api",
"key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
WebResource webResource =
client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
"/messages");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", "Excited User <me@samples.mailgun.org>");
formData.add("to", "bar@example.com");
formData.add("to", "baz@example.com");
formData.add("subject", "Hello");
formData.add("text", "Testing some Mailgun awesomness!");
return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
post(ClientResponse.class, formData);
}
How can I do the same thing with Play's WS api?