Skip to content

Instantly share code, notes, and snippets.

@sheharyarn

sheharyarn/APIClient.java

Last active Aug 29, 2015
Embed
What would you like to do?
Using AndroidAsyncHttp Library
RequestParams params = new RequestParams();
params.put("email", "a@b.c");
params.put("password", "12345678");
APIClient.post("/login", params, new JsonHttpResponseHandler() {
// @Override them all
public void onStart() { } // Runs before anything else
public void onFinish() { } // Runs after everything else
// If don't know your response type
public void onSuccess(int statusCode, Header[] headers, byte[] response) { }
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { }
// If your responses are simple text
public void onSuccess(int statusCode, Header[] headers, String response) { }
public void onFailure(int statusCode, Header[] headers, String error, Throwable throwable) { }
// If your responses are JSON Objects (or Arrays)
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { }
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject error) { }
public void onSuccess(int statusCode, Header[] headers, JSONArray response) { }
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errors) { }
// Fuck me, right?
// You can use more than one at a time
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment