Could any one please suggest a better open source Java API for invoking REST services? Also wanted to know if Restlet API supports NTLM authentication.
Thanks
Could any one please suggest a better open source Java API for invoking REST services? Also wanted to know if Restlet API supports NTLM authentication.
Thanks
It's REST - the whole point is you don't need an API per se, just HttpURLConnection. You should be able to interact with any truly RESTful service with the basic Java SDK alone. You can get fancier with Apache Commons HTTPClient - but it's not a necessity.
Check out Restlet. It has a good client API.
Example usage:
Request request = new Request(Method.GET, "http://my/rest/api");
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
//get response representation and process
If you only wish to invoke a REST service and get the response you can try out REST Assured:
// Make a GET request to "/lotto"
String json = get("/lotto").asString()
// Parse the JSON response
List<String> winnderIds = with(json).get("lotto.winners.winnerId");
// Make a POST request to "/shopping"
String xml = post("/shopping").andReturn().body().asString()
// Parse the XML
Node category = with(xml).get("shopping.category[0]");
I am using resteasy as the rest frameworks and it works just fine and easy (both to rewrite and to test, same as easymock). As a sample code:
@Path("/webservice")
public class Web
{
@GET
@Path("{web}")
@ProduceMime("application/xml")
public String test(@QueryParam("param") String param, @PathParam("web") String web)
{
// code here
}
}
So this get will receive a call from /webservice/web?param=lalala and return a string in the application/xml format