title: Convert String to GET request Parameter in Dart using standard library
body: <p>I have a multiword String that I'd like to convert to a GET request parameter. </p>
  
  <p>I have an API endpoint <code>/search</code> that takes in the parameter <code>query</code>. Now typically your request would look like <code>http://host/search?query=Hello+World</code>.</p>
  
  <p>I have a <code>String</code> <em>Hello World</em> that I'd like to convert to this URL encoded parameter. </p>
  
  <p>Ofcourse, I could just write the logic to break it into words and add a <code>+</code> in between but I was wondering if the <a href="https://api.dartlang.org/stable/1.20.1/dart-core/Uri-class.html" rel="noreferrer">URI class could help with this</a></p>
  
  <p>I'm using Dart's <code>httpClient</code> to make a request.</p>
  
  <pre><code>Future&lt;String&gt; _getJsonData(String queryToSearch) async {
    List data = new List();
    var httpClient = new HttpClient();
  
    var request = await httpClient.getUrl(Uri.parse(
        config['API_ENDPOINT'] + '/search?query=' +
            queryToSearch));
  
    var response = await request.close();
    if (response.statusCode == HttpStatus.OK) {
      var jsonString = await response.transform(utf8.decoder).join();
      data = json.decode(jsonString);
      print(data[0]);
      return data[0].toString();
    } else {
      return "{}";
    }
  }
  </code></pre>
  
  <p>Essentially, need to encode <code>queryToSearch</code> as the URL parameter. </p>