-1

I'd like to make calls to rest apis provided by parse using java. Is there any api in java can do this? I'm totally new to this kind of rest api call stuff.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Fihop
  • 3,127
  • 9
  • 42
  • 65

4 Answers4

1

I have done well with Jersey: https://jersey.java.net

With Jersey you can create a server-side REST API as well a REST client, which is what you want. See the documentation at https://jersey.java.net/documentation/latest/client.html

Tom
  • 3,913
  • 19
  • 28
  • What I want to do is very easy. I know the url and it's a POST call. I also need to set some headers(The API key stuff) and some parameters for the POST call. Can you give me a hint what kind of api in Jersey is used to do this? – Fihop Jul 12 '13 at 13:40
1

Jersey is a good choice. It's an industry standard, the reference implementation and easy to use.

Here is a good tutorial with a simple helloworld example: http://www.vogella.com/articles/REST/

  • 1
    @SotiriosDelimanolis It has a client part as well. See section 5.5 in the linked document. – herman Jul 11 '13 at 22:14
  • @MelanieMunden What I want to do is very easy. I know the url and it's a POST call. I also need to set some headers(The API key stuff) and some parameters for the POST call. Can you give me a hint what kind of api in Jersey is used to do this? – Fihop Jul 12 '13 at 13:41
  • @herman What I want to do is very easy. I know the url and it's a POST call. I also need to set some headers(The API key stuff) and some parameters for the POST call. Can you give me a hint what kind of api in Jersey is used to do this? – Fihop Jul 12 '13 at 13:42
  • @FihopZz I edited this answer to add info on doing a POST call and add headers (wait for the edit to be accepted). – herman Jul 16 '13 at 08:49
  • @herman, where can I see your answer? – Fihop Jul 16 '13 at 18:39
  • @FihopZz it didn't get accepted. But look at the example in section 7.5 in the linked page. It uses `WebResource.post(...)` to do the POST request. Similarly, you can add headers using `WebResource.headers` (note: it's a fluent API) – herman Jul 17 '13 at 01:02
0

You can try RESTEasy as a rest client library: http://www.jboss.org/resteasy

Jan Martiška
  • 1,151
  • 5
  • 7
0

Spring has a great support for REST.It provides you the RestTemplate which avoids lot of boiler plate code when invoking a Rest API from the Client code.Below is an example

public class Client{
    RestTemplate restTemplate;
    public void callRestService() {
    ResponseObj obj = (ResponseObj) restTemplate.getForObject("rest url",ResponseObj.class,"urlVariables");  
}

}

ak123
  • 285
  • 2
  • 5
  • 15
  • Hi Anirudh. Thanks for your help. I have one more question for your code snippet. How can I add headers to the call?, I need to add API key and other stuff to make the call. – Fihop Jul 12 '13 at 13:50
  • sorry for responding late on this.HttpEntity object which is passed as one of the parameters encapsulate the header information.Refer to spring API documentation about the HttpEntity object and how to set headers – ak123 Jul 22 '13 at 04:58