Skip to content

Instantly share code, notes, and snippets.

@meshileya
Created October 25, 2018 12:34
Show Gist options
  • Save meshileya/27f884a55a822149506a4257c49f1ef8 to your computer and use it in GitHub Desktop.
Save meshileya/27f884a55a822149506a4257c49f1ef8 to your computer and use it in GitHub Desktop.
public interface RegistrationAPI {
@FormUrlEncoded
@POST("/ServerBackyard/insert_details.php")
public void addUser(
@Field("email") String email,
@Field("name") String name,
@Field("username") String username,
@Field("password") String password,
Callback<Response> callback);
}
private void addUser(){
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(BASE_URL) //Setting the Base URL
.build();
RegisterAPI api = adapter.create(RegistrationAPI.class);
api.addUser(
editTextEmail.getText().toString(),
editTextUsername.getText().toString(),
editTextPassword.getText().toString(),
editTextName.getText().toString(),
new Callback<Response>() {
@Override
public void success(Response result, Response response)
BufferedReader reader = null;
String result = "";
try {
reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
output = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
@Override
public void failure(RetrofitError err) {
//If any error occured displaying the error as toast
Toast.makeText(MainActivity.this, err.getMessage,Toast.LENGTH_LONG).show();
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment