Is it possible to use a REST or web api in a java Swing application

19,512

Solution 1

Yes. It is possible.

You can Consume (access and read) a REST web service in Swing desktop application.

You can achieve it using HTTPClient.

An example - http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-apache-httpclient/

Solution 2

Use Spring RestTemplate an example here.

RestTemplate rest = new RestTemplate()
rest.postForObject("http://localhost:8080/WebApp/ServiceName", requestBean, Response.class);

This should return an object of type Response. For other HTTP operations supported by RestTemplate see the Spring documentation.

Solution 3

You can grep this example: Creating RESTful Service Clients in NetBeans Modules. The example shows how to create a twitter java-swing based desktop client with OAuth support (SWING).

Also you can grep this video tutorial for eclipse platform (SWT)

Here is a JavaFX example for RestFULL client

There is very good example of rest desktop client in RESTful Java Web Services by Jose Sandoval. Try it on google/books

Share:
19,512
rasen58
Author by

rasen58

I like programming and apple pie

Updated on June 17, 2022

Comments

  • rasen58
    rasen58 almost 2 years

    I have a Swing application that is done except for the web api part. They have a REST api, but when I was looking at example of using a REST api in java, they all use a java web application, and I can't find any for a desktop swing application. So is it still possible to do so?

    • assylias
      assylias over 9 years
      Do you want to expose or to consume a web service?
  • Samuel Owino
    Samuel Owino almost 7 years
    Thanks so much @Ninad this was very helpful,