title: Fetch content from (WordPress) api in sapper
body: <p>I am working with the sapper start template <a href="https://github.com/sveltejs/sapper-template" rel="nofollow noreferrer">https://github.com/sveltejs/sapper-template</a> and confused on how to approach fetching data from an external API (in this case WordPress). </p>
  
  <p>I have modified /blog/_posts.js this contained <code>const = posts = [...all the json..]</code> - first I tried replacing this with <code>const = posts = fetch('http://localhost:9000/wp-json/wp/v2/posts');</code>  which gives an error fetch is not defined - so I included node-fetch - which now returns an error in server <code>js posts.map is not a function</code></p>
  
  <p>I have been reading to try and find an answer and tried things like:</p>
  
  <pre class="lang-js prettyprint-override"><code>let posts;
  export async function preload(page, session) {
      posts = await this.fetch('http://localhost:9000/wp-json/wp/v2/posts');
      return { posts }; 
  }
  export default posts;
  </code></pre>
  
  <p>from <code>_posts.js</code> which results in:</p>
  
  <pre class="lang-js prettyprint-override"><code>const contents = JSON.stringify(posts$1.map(post =&gt; { 
      TypeError: Cannot read property 'map' of undefined
  </code></pre>
  
  <p>Unfortunately I cannot find any documentation or examples how to do this - so reaching out as I try to learn sapper, advice is greatly appreciated.</p>