Skip to content
Cliente Android para hacer peticiones a servicios REST.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
RestazoClient.java

README.md

RestazoClient v1b José M. Carnero

===

Cliente REST para Android.

É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.

  • Peticiones asíncronas.
  • Tanto la URL del servicio REST, como el método de petición y los parámetros son asignables.
  • Desacoplada, realiza las acciones necesarias mediante callback.

Ejemplo:

RestazoClient.RestazoClientCallback resCallback = new RestazoClient.RestazoClientCallback() {
    @Override
    public Boolean onCallback(Map<String, Object> 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.

==== In English:

REST client for Android.

This library makes asynchronous REST requests. Returns data (or errors, if occurs) has a hashmap.

While functional it is still in beta stage; There is much to do.

  • Asynchronous request.
  • REST service URL, request method and request parameters are assigned on each petition.
  • Decoupled, make the work with an user callback.

Example:

RestazoClient.RestazoClientCallback resCallback = new RestazoClient.RestazoClientCallback() {
    @Override
    public Boolean onCallback(Map<String, Object> aResult){
        TextView tvInfo = (TextView)findViewById(R.id.textView_info);

        String sText = "Loading...";

        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 = "Request finished";
                tvInfo.setVisibility(View.INVISIBLE);
            }

            tvInfo.setText(sText);
        }

        return true;
    }
};

new RestazoClient(resCallback).execute("http://example.com/rest", "post", "param1=0", "param2=5");

If no parameters or type of request (GET by default) are required, it can be called with:

new RestazoClient(resCallback).execute("http://example.com/rest");

Tested on Android 4.4.

You can’t perform that action at this time.