title: How to use my api key with a loader?
body: <p>I already have an app that uses loaders for an api but I want to adapt it for a new api. The problem is that the new api was given to me in this format:</p>
  
  <pre><code>curl -H "Authorization: Token &lt;myToken&gt;" "https://localelections.usvotefoundation.org/api/v1/states"
  </code></pre>
  
  <p>which I can use just fine in the terminal but I don't know how to use it in Android Studio. Can anybody point me in the right direction?</p>
  
  <p>Some code from my Utils file:</p>
  
  <pre><code>// Returns new URL object from the given string URL.
  private static URL createUrl(String stringUrl) {
      URL url = null;
      try {
          url = new URL(stringUrl);
      } catch (MalformedURLException e) {
          Log.e(LOG_TAG, "Problem building the URL ", e);
      }
      return url;
  }
  
  //Make an HTTP request to the given URL and return a String as the response.
  private static String makeHttpRequest(URL url) throws IOException {
      String jsonResponse = "";
  
      // If the URL is null, then return early.
      if (url == null) {
          return jsonResponse;
      }
  
      HttpURLConnection urlConnection = null;
      InputStream inputStream = null;
      try {
          urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.setReadTimeout(10000 /* milliseconds */);
          urlConnection.setConnectTimeout(15000 /* milliseconds */);
          urlConnection.setRequestMethod("GET");
          urlConnection.connect();
  
          // If the request was successful (response code 200),
          // then read the input stream and parse the response.
          if (urlConnection.getResponseCode() == 200) {
              inputStream = urlConnection.getInputStream();
              jsonResponse = readFromStream(inputStream);
          } else {
              Log.e(LOG_TAG, "Error response code: " + urlConnection.getResponseCode());
          }
      } catch (IOException e) {
          Log.e(LOG_TAG, "Problem retrieving the JSON results.", e);
      } finally {
          if (urlConnection != null) {
              urlConnection.disconnect();
          }
          if (inputStream != null) {
              // Closing the input stream could throw an IOException, which is why
              // the makeHttpRequest(URL url) method signature specifies than an IOException
              // could be thrown.
              inputStream.close();
          }
      }
      return jsonResponse;
  }
  </code></pre>