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

I have a Swing application that runs, except for the api web part. They have a REST api, but when I looked at an example of using a REST api in java, they all use a java web application and I cannot find it for a desktop application. So can this be done?

+5
source share
3 answers

Yes. It is possible.

You can use (view and read) the REST web service in a working Swing application.

You can achieve this using HTTPClient .

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

+8
source

Use the Spring RestTemplate 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 Spring Documentation.

+7
source

You can grep this example : creating RESTful Service clients in NetBeans modules. This example shows how to create a java-swing twitter-based client client with OAuth support (SWING).

You can also grep this video tutorial for the eclipse platform (SWT)

Here is a JavaFX example for a RestFULL client

There is a very good example of a desktop client for a vacation at RESTful Java Web Services, Jose Sandoval. Try it on google / books

+1
source

Source: https://habr.com/ru/post/1200225/


All Articles