5

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

digitaljoel
  • 26,265
  • 15
  • 89
  • 115

4 Answers4

7

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.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
Gandalf
  • 9,648
  • 8
  • 53
  • 88
  • 1
    It's not a necessity, but neither is an IDE, the point is that there are libraries to deal with the hard parts (HTTPS, representation processing etc) so you can focus on delivering functionality – Rich Seller Aug 17 '09 at 19:36
  • Developing an app with an relatively small footprint (2mb total package including graphical assets), I am definitely trying to avoid adding additional libraries/licensing so this is helpful to me! – Yablargo Dec 16 '11 at 16:48
4

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
Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • 2
    I agree. Also, the new version of Restlet which is under development, and nearing release, 2.0, also supports a new approach to "calling" resources — client-side resources. In other words, you can instantiate a resource object with the URL of the remote resource, and then get a representation of it, send a new representation, etc. I haven't used it yet, but I'm intrigued by it. – Avi Flax Aug 19 '09 at 13:24
1

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]");
Johan
  • 37,479
  • 32
  • 149
  • 237
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
    }
}
  • @Path is your "root path" of the class (your real "root" would be configured on components.xml)
  • @GET is from Rest
  • ProduceMime or ConsumeMime is the mime you should consume or produce
  • @QueryParam is the params of the url and @PathParam the parameters you should get

So this get will receive a call from /webservice/web?param=lalala and return a string in the application/xml format

Diego Dias
  • 21,634
  • 6
  • 33
  • 36