NickUnique
NickUnique

Reputation: 93

Retrofit query parameters

I need to get movies from OMBD api database. In main activity I have recycler view and toolbar with menu item search implemented by widget SearchView.

I need to type the title of the movie in the search menu item and send that request to the server

I have url like this https://omdbapi.com/?s=title&apikey=123456bb where title should be inserted by the user via search menu item.

I want to ask how can I define the endpoints using retrofit when my base url is:http://omdbapi.com

@GET("https://www.omdbapi.com")
Call<Movie> search(@Query("s") String keyword, @Query("apikey") String apikey);

Something like this?

Upvotes: 0

Views: 230

Answers (1)

copolii
copolii

Reputation: 14506

You define your base url when you are creating your Retrofit instance:

final OMBDApi api = new Retrofit.Builder()
    .baseUrl("https://omdbapi.com/")
    .build()
    .create(OMBDApi.class);

Inside the @Get (or other interface methods) you just put the relative path. If you have fixed query parts, you can just throw them in the relative url:

@Get("?apikey=<your_api_key>")
Call<Movie> search(@Query("s") String keyword);

Upvotes: 1

Related Questions