I am trying to access my backend API generated with Loopback's generator. I am using the in-memory database to store the data. Currently, I am testing it locally. When I try to create new instance of "Feature" I get this error in the callback:
D/AsyncHttpClient: Headers were overwritten! (Accept | application/json) overwrites (Accept | application/json)
V/AsyncHttpResponseHandler: Progress 210 from 210 (100%)
W/remoting.RestAdapter: HTTP request (string) failed: org.apache.http.client.HttpResponseException: Not Found
/xdesign.georgi.espc E/MainActivity: onError - org.apache.http.client.HttpResponseException: Not Found
This is a diagram of my models
My MainActicity looks like that:
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private Model feature;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://10.0.2.2:8080/api");
ModelRepository featureRepository = adapter.createRepository("Feature");
feature = featureRepository.createObject(ImmutableBiMap.of("name","ANDROID_TEST"));
feature.save(new VoidCallback() {
@Override
public void onSuccess() {
Log.e(TAG,"onSuccess");
}
@Override
public void onError(Throwable t) {
Log.e(TAG,"onError - " + t.toString());
}
});
}
}
Figured it out. I've got an onSuccess response when I changed the URL to the "server" to
http://10.0.2.2:3000/api
Apparently, we need to use port 3000 in order to get it to work.