• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query a database with RetroFit

 
jawann jefferson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am currently trying to make an app. All I want it to do is query a database for information and display that information. Seems pretty simple right? Not if you are new to web services. :-/. What I am trying to do is use RetroFit to make that call since it does all the json parsing and puts it in a nice POJO for you. What i can't figure out is how to query the database using the Retrofit library.

Retrofit has a Query command but i am not sure if thats what i am looking for. I've looked at ton of tutorials on youtube and read online but i can't seem to get a straight answer. It could also be my lack of knowledge on the subject as well.

I've created the interface:
public interface LanIscAPI {

@GET("/feed/lanisc.json")
public void getFeed(Callback<List<DataObjects>> response);

Here is my implementation
private void requestData(String uri)
{

//RestAdapter is included in the RetroFit Lib
//We are goin to instantiate the object and pass in ENDPOINT constant then call the build method
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(ENDPOINT).build();
LanIscAPI api = adapter.create(LanIscAPI.class); //Passing in class property of API interface
//defines where my web service is and how i want to call it. Bring in API interface you defined

api.getFeed(new Callback<List<DataObjects>>() { //Callback saying it is going to return a list of our dataobjects


//Retrofit does everything. Handles Async processing, Retrieves content from webservice which starts as a string
//It parses it as JSON and transforms it to list of objects (arg0)


@Override
public void success(List<DataObjects> arg0, Response arg1) {
// TODO Auto-generated method stub

dataList = arg0; //Since retrofit transforms our data all we need to do it place it in the list
updateDisplay();

}

@Override
public void failure(RetrofitError arg0) {
// TODO Auto-generated method stub

}
});


}

I ask that you please be patient with me as i am learning all of this for the first time. Sorry for all the comments. i use the comments to help me understand what is going on.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic