title: Traversing an api with java calls
body: <p>I am attempting to traverse an api recursively to produce an end result of the type:</p>
  
  <pre><code>     1
      / \  \  \
     /   \  \  \
    /     \  \  \
   2       3  0  7
   \     /        \
     4   5   6     10
    /       / \
   7       8   9
  </code></pre>
  
  <p>The issue I am finding is that I understand that I can use something similar to <a href="http://rosettacode.org/wiki/Tree_traversal#Java" rel="nofollow">http://rosettacode.org/wiki/Tree_traversal#Java</a>
  But fail to understand how to recursively make a NEW call on the api?</p>
  
  <p>The API accepts the following input:
  <a href="http://example.com/1/children" rel="nofollow">http://example.com/1/children</a></p>
  
  <p>To return:</p>
  
  <pre><code>{
      "name": "1",
      "children": [{
          "name": "2"
      }, {
          "name": "3"
      }]
  
  }
  </code></pre>
  
  <p>How would I then continue to make a call on 2 to find it's children and then do the same for 3 once all the children for 2 are found?</p>
  
  <p>Sample code:</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  
  public class URLConnectionReader {
      public static void main(String[] args) throws Exception {
          URL yahoo = new URL("http://example.com/1/children");
          URLConnection yc = yahoo.openConnection();
          BufferedReader in = new BufferedReader(
                                  new InputStreamReader(
                                  yc.getInputStream()));
          String inputLine;
  
          while ((inputLine = in.readLine()) != null) 
              System.out.println(inputLine);
          in.close();
      }
  }
  </code></pre>