Imogen Cunningham
Proyecto en GitHub: github.com/jmcarnero/RestazoClient
Ésta librería permite realizar peticiones a servicios REST de forma asíncrona. Devuelve los datos recuperados (o los errores, si fuera el caso) como hashmap.
Si bien es funcional todavía está en fase beta; queda mucho por hacer.
RestazoClient.RestazoClientCallback resCallback = new RestazoClient.RestazoClientCallback() {
@Override
public Boolean onCallback(Map aResult){
TextView tvInfo = (TextView)findViewById(R.id.textView_info);
String sText = "Cargando...";
if (!aResult.isEmpty()) {
String sStatus = (String) aResult.get("status");
String sError = (String) aResult.get("error");
if (sError != null && !sError.isEmpty()) {
tvInfo.setText("Error: " + sError);
return false;
}
sText = sStatus;
if (sStatus.equals("done")) {
sText = "Finalizada recuperación";
tvInfo.setVisibility(View.INVISIBLE);
}
tvInfo.setText(sText);
}
return true;
}
};
new RestazoClient(resCallback).execute("http://example.com/rest", "post", "param1=0", "param2=5");
Si no se requieren parametros ni tipo de petición (GET por defecto) puede llamarse con:
new RestazoClient(resCallback).execute("http://example.com/rest");
Testeo en Android 4.4.