I have a local WEB API in c# running in VS17, that runs and accesses a DB in SQL express using the basic HTTP methods.
And on the other hand I want (have the basics of) an android app that is supposed to access the API and just produce a simple GET requests (currently using Retrofit) and then display the data that was retrieved. Everything works fine on the back-end (tested with postman).
But I haven't had any success in being able to access my API via the app. Any guidance on where I need to look to or how to start would be great!
Notes: API is locally hosted SQLEXpress DB is local Android Device is an emulator I need to use SQLExpress as to SQlite private final String BASE_URL = "http://10.0.2.2:60060";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.pagination_list);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
EmployeeAPIClient client = retrofit.create(EmployeeAPIClient.class);
Call<List<Employee>> call = client.allEmployees();
call.enqueue(new Callback<List<Employee>>() {
@Override
public void onResponse(Call<List<Employee>> call, Response<List<Employee>> response) {
List<Employee> employees = response.body();
Log.w("MainAct onResponse():", " response method called.");
if(employees.size() <= 0){
Log.w("EMPTY", " List is empty..");
}else {
for(Employee emp: employees){
Log.d("FirstName: " , emp.getFirstName());
Log.d("LastName: " , emp.getLastName());
Log.d("Gender: " , emp.getGender());
Log.d("Salary: " , emp.getSalary());
}
//listView.setAdapter(new EmployeeAdapter(MainActivity.this, employees));
}