Home > Blockchain >  how to input text parameter to GET api with space
how to input text parameter to GET api with space

Time:05-16

I have an http service to GET movies api data it works fine but if i input 2 words for example "The Batman" it's not working because it will return null but if i only input 1 word "Batman" it works fine, im still new with query query things

if you have the answer can you please answer with my full code ? because im quite slow to understand some logic

here is my code

Future searchMovie(movieName) async {

Uri url = Uri.parse('https://api.themoviedb.org/3/search/movie?api_key={key}&query=$movieName');

var response = await http.get(url);
if (response.statusCode == 200) {
  List data = jsonDecode(response.body)['results'];
  List<SearchMovieModel> searchedMovies = [];

  for (var item in data) {
    searchedMovies.add(SearchMovieModel.fromJson(item));
  }

  return searchedMovies;
} else {
  throw Exception('Error get data');
}

}

CodePudding user response:

you can try this way.

  String query ='The Batman';
  await get(Uri.parse('https://api.themoviedb.org/3/search/movie').replace(
     queryParameters:  {
       'api_key' :'key',
        'query' : query    
       }
  ));

CodePudding user response:

URL encoded equivalent of space is try The Batman

  • Related