I am working on a java client that makes REST aPI alls to an API server . Every time it requests an API it authenticates itself with an auth token.
I want to wrap this information in a sessions object to have it handy for objects making RESt calls
public class MySession {
public static String api_endpoint ;
public static String username ;
public static String password ;
public MySession(String api_endpoint,
String auth_endpoint, S
String username, String password,) {
this.api_endpoint = api_endpoint;
this.auth_endpoint = auth_endpoint;
this.username = username;
this.password = password;
}
public String getAuthToken() {
// use the mySession.user and mySession.pass to get the auth token
return authToken;
}
}
public class MyOtherClass {
MySession mysession;
public (MySession msession) {
this.mysession = msession;
}
public void makeRestCall() {
String token = msession.getAuthToken();
// use token and make REST call
}
Is this the right way to write the getAuthToken method? Is there any flaw in my design?
Aucun commentaire:
Enregistrer un commentaire