‫Hello, my friends, and welcome back.
‫In this video, we're going to talk about the Http query parameters.
‫Query parameters are a defined set of parameters attached to the end of a URL.
‫So for example, we have this link, example.com slash widgets and we have the question mark.
‫The question mark represents the start of parameters.
‫The first.
‫Parameter, which is which is in a key value pairs.
‫It's called color.
‫Equal is the separation between the key and the value.
‫And the blue is the value and is a separator for another.
‫Parameter, which is the sort as a key and the value is the newest.
‫They are extensions of the URL that are used to help define specific content or actions based on the
‫data being passed to append query parameters to the end of the URL.
‫A This question mark.
‫As is added, followed immediately by a query parameter to add multiple parameters.
‫An ad sign is added in between each.
‫These can be created by any variation of object types or lengths such as strings, arrays and numbers.
‫The following is an example.
‫We have here.
‫The query string begins the first variable name key one equal value one and which is the separator key
‫two equal to the value two.
‫To add multiple parameters and add sign is added in between each of these parameters.
‫This is a very important point.
‫So let me jump into Android studio and I will tell you why we should use these parameters.
‫So after we.
‫Run our application here.
‫For example, if this title corresponds to a user ID, if we open the Json file, we see that the ID,
‫the user ID is one has.
‫This title and this object.
‫And this object.
‫This object.
‫This.
‫And.
‫And so on.
‫This.
‫Are the albums for the first user, which is the user ID one.
‫And there are a lot of users.
‫Then if I want to display, for example.
‫The data or the albums for the user ID one only.
‫I don't need to display the user ID to albums and so on.
‫I need only to display the first ten which corresponds to the user ID number one.
‫I need to use these parameters, so please concentrate with me.
‫I told you that the parameters and the query parameters starts with the question mark.
‫Here we put the.
‫Key, which is the user ID, and it's case sensitive.
‫User ID equal to one.
‫This is the key.
‫And this is the value.
‫If I hit Enter now.
‫Then it will displays for me.
‫It will display for me the albums that are for the user ID number one.
‫You can see that we are displaying only ten objects.
‫Okay.
‫It's very simple.
‫If I need to to get the user ID albums equal to five hit enter, you can see the albums.
‫This is the first album, second album, third, fourth and so on.
‫These are the albums of number five.
‫Okay, you can see how it's very simple.
‫We start with the question mark.
‫We start put here the key and equal sign, and here is the value key value pairs.
‫Now going back to retrofit, how to make this thing happen in or happens in this retrofit library.
‫It's very simple.
‫It's the same.
‫We go to the album service and here I should deal with every endpoint.
‫So this is.
‫This query is considered as an endpoint query.
‫So for that I refer to the interface album service.
‫I will start with get.
‫And here I'm getting data from the server and here also I need to use the album's end point, but in
‫this time I need.
‫To specify the query get.
‫Specific.
‫Albums.
‫And here I will use the annotation query.
‫This will understand or tell the android studio that I am going to get the albums.
‫End point using the query.
‫So it will put.
‫The query sign for it, so I'm adding the query annotation.
‫What is the key that we have created the query.
‫Its user ID, So I will put here the user ID and it's case sensitive.
‫And what is the value?
‫User id dot or type int.
‫I specify the user id.
‫As an integer.
‫You can see that it's number five.
‫Okay, So this is the key and this is the value.
‫I'm telling Android studio to create a query, a get get method at first.
‫This is the endpoint I'm adding to with a query.
‫Which is the question mark.
‫This is the key and this is the value.
‫And later on, I need to get back as a response of albums, of course.
‫So I need to get the response.
‫These are.
‫Objects included inside this array.
‫So don't miss the syntax of the Json.
‫You can see that it starts with an array, so I should return a response of type albums.
‫And the albums is an array list that it's similar to the hierarchy of that Json file.
‫Okay.
‫I hope you understand it well.
‫Now let's go back to our main activity.
‫And here I need to.
‫The comment this I will create a new val.
‫Response to equal to retrofit service dot get specific albums and here I will pass the ID, the user
‫ID as six, and here I will emit the response to.
‫Let me close everything.
‫Now let me run the application and here I will make the query.
‫Six So I am going to display.
‫And we can see these are the objects and the albums that corresponds to the user ID equal to six.
‫Let me run the application again.
‫There is an error.
‫Let me check.
‫And here we go.
‫These are the objects.
‫I think I was having an error.
‫In the Internet connection.
‫So if I run the application again, it will work fine.
‫You can see these are ten albums.
‫You can see here we have received them for the user ID number six.
‫So these are the query parameters.
‫And here how we pass the specific query parameters for getting.