‫Back to our Json response.
‫If we look closer, we have this square bracket.
‫So our response starts with the square bracket indicating that the whole response is an array Json array.
‫And inside this array we have this first object, and this is the second Json object separated by the
‫comma.
‫We can't directly serialize and deserialize this Json object using this question class, because this
‫question class has six fields and these are indicating the object.
‫This.
‫But this object is nested from the array.
‫So the solution for this problem is to create another modal class.
‫So inside this modal package I'll create a new Java class and I'll name it as question list.
‫This is an empty class.
‫I'll extend it from array list because we have a nested objects inside this array, because our response
‫starts with this array, and there is no key for this array.
‫So I can directly use this empty class.
‫It's of type question import the array list class.
‫And here we go.
‫This is our second modal class called question list.
‫It's an empty class just to get the response and include this response.
‫Because the response the API response and the Json response start with this square bracket.
‫No key or value is directly a value of an array.
‫Back to the retrofit steps.
‫We added the data classes.
‫Now let's move to create the API service interface.
‫We need to create an interface to define our different methods that will be used for network transactions.
‫I'll create a new package, I'll name it as retrofit.
‫And inside this retrofit package I'll create a new interface and I'll name it as questions API.
‫A retrofit API service interface is an essential component used to define the structure and behavior
‫of network requests to a RESTful API.
‫This interface acts as a contract, as a bridge between your Android application and the web service,
‫specifying the available API endpoints and the expected response format.
‫The retrofit then uses this interface to create the necessary implementation for making network requests.
‫Each method inside this interface should specify the Http request method either get, post, put, delete,
‫and the endpoint URL relative to the base URL, and any required query parameters, request bodies,
‫or headers.
‫You can also specify the expected response form.
‫In this example, I'll use apt get.
‫Again, guys, I want from you to focus with me and please refer to the previous sections and especially
‫the mVVM plus retrofit in order to understand all these Http requests and responses.
‫And also I clarified them in very deep detail.
‫So please go back to the mVVM plus retrofit section and get details about these terms.
‫But don't worry, I'll clarify everything.
‫I write the annotation get specify the Http method and the relevant parts of the URL.
‫Here I need to define the endpoint.
‫So if we go back to the response the endpoint.
‫Here is my quiz API dot php.
‫So I'll copy it and I'll paste it here.
‫This is the end point.
‫Then I'll use coal and the retrofit to.
‫And here I need to specify questions list question list.
‫It's a class that we created before and I'll name the method get questions.
‫In retrofit, the coal class is used to wrap a network request and represents the result of an asynchronous
‫operation.
‫The generic type question list represents the expected response type, and I am expecting this response
‫from the API starting with this square bracket, which is a Json array.
‫This is the name of the method get questions.
‫So it's returning type is call of questions list.
‫When calling this method get questions, it will send a network request and expect to receive a response
‫of type question list.
‫And this question list acts as a structure of the response data you expect from the API.
‫And as said before.
‫For we are expecting an array without a key value pairs.
‫It's directly an array of Json response.
‫So for that we use this empty class that extends from array list of quests.
‫So here I'm expecting to get a question list structure.
‫Again.
‫This method get questions is defined to send a network request to a specific API endpoint, which is
‫my quiz API dot PHP and expects a response in the form of a call containing the question list.