How to login with a REST API server from gluon mobile application. I have tried HttpClient which does able to call .
Asked
Active
Viewed 942 times
1 Answers
2
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.

AhaMoment
- 73
- 6
-
what is user.class here ? – Amit Aug 08 '16 at 12:06
-
User.class is a POJO. You must provide this to match the object being returned. [Retreive Object](http://docs.gluonhq.com/connect/1.0.0/#_retrieving_an_object) – AhaMoment Aug 08 '16 at 19:15
-
How i will use `ProgressIndicator` for background progress . – Amit Aug 09 '16 at 12:50
-
I haven't found anything for the DataProvider that gives a progress value. Use the Indeterminate progress indicator. – AhaMoment Aug 12 '16 at 17:28