title: HTTP requests and Rest API in Flutter
body: <p>First of all, I have been trying to get a HTTP request in Flutter, and i have no experience in JavaScript.</p>
  
  <p>A Website only provides a JavaScript sample code but i don't how to use it for Flutter.</p>
  
  <p><a href="https://kodestat.gitbook.io/flutter/flutter-http-requests-and-rest-api" rel="nofollow noreferrer">https://kodestat.gitbook.io/flutter/flutter-http-requests-and-rest-api</a></p>
  
  <p>I tried the above link but failed.</p>
  
  <p>I know i have to insert URL and ServiceKey like this.</p>
  
  <pre><code>class HomePageState extends State&lt;HomePage&gt; {
  
    //this async func will get data from the internet
    //when our func is done we return a string
    Future&lt;String&gt; getData() async {
      //we have to wait to get the data so we use 'await'
      http.Response response = await http.get(
        //Uri.encodeFull removes all the dashes or extra characters present in our Uri
        Uri.encodeFull("URL"),
        headers: {
          //if your api require key then pass your key here as well e.g "key": "my-long-key"
         "Accept": "application/json" 
         "key": "my-long-key"
        }
      );
  
      //print(response.body);
  
      List data = json.decode(response.body);
      //print(data);
      print(data[1]["title"]);
    }
  </code></pre>
  
  <p>But how should i handle encodeURIComponent and other functions in Flutter to get a HTTP request?</p>
  
  <p>Here is JavaScript sample code.</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  var url = 'http://openapi.tago.go.kr/openapi/service/ArvlInfoInqireService/getSttnAcctoArvlPrearngeInfoList'; /*URL*/
  var queryParams = '?' + encodeURIComponent('ServiceKey') + '='+'ServiceKey'; /*Service Key*/
  queryParams += '&amp;' + encodeURIComponent('cityCode') + '=' + encodeURIComponent('25'); /*CityCode*/
  queryParams += '&amp;' + encodeURIComponent('nodeId') + '=' + encodeURIComponent('DJB8001793ND'); /*nodeID*/
  xhr.open('GET', url + queryParams);
  xhr.onreadystatechange = function () {
      if (this.readyState == 4) {
          alert('Status: '+this.status+' Headers: '+JSON.stringify(this.getAllResponseHeaders())+' Body: '+this.responseText);
      }
  };
  
  xhr.send('');
  </code></pre>