如何在gluon javafx应用程序中处理异步API调用(How to handle a async API call in gluon javafx Application)

编程入门 行业动态 更新时间:2024-10-24 01:52:59
如何在gluon javafx应用程序中处理异步API调用(How to handle a async API call in gluon javafx Application)

如何使用gluon移动应用程序登录REST API服务器。 我试过能够调用的HttpClient。

How to login with a REST API server from gluon mobile application. I have tried HttpClient which does able to call .

最满意答案

要访问REST API,您可以使用RestClient。

import com.gluonhq.connect.provider.RestClient; RestClient restClient = RestClient.create() .host("http://myhost.com") .path("restservice/login") .queryParam("username","myname") .queryParam("password","myencodedpassword") .method("GET"); GluonObservableObject<User> sample = DataProvider.retrieveObject(restClient.createObjectDataReader(User.class));

然后,要处理结果,可以使用stateProperty

sample.stateProperty().addListener((obv,ov,nv)->{ if(nv.equals(ConnectState.SUCCEEDED)){ User loggedInUser = sample.get(); } });

你也可以使用initializedProperty。

RestClient JavaDoc

To access a REST API you can use RestClient.

import com.gluonhq.connect.provider.RestClient; RestClient restClient = RestClient.create() .host("http://myhost.com") .path("restservice/login") .queryParam("username","myname") .queryParam("password","myencodedpassword") .method("GET"); GluonObservableObject<User> sample = DataProvider.retrieveObject(restClient.createObjectDataReader(User.class));

To then handle the result you can use the stateProperty

sample.stateProperty().addListener((obv,ov,nv)->{ if(nv.equals(ConnectState.SUCCEEDED)){ User loggedInUser = sample.get(); } });

you can use initializedProperty as well.

RestClient JavaDoc

更多推荐

本文发布于:2023-08-05 05:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427254.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   如何在   gluon   javafx   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!