title: API requests in svelte
body: <p>I'm a bit new to svelte and javascript. I'm trying to build a page with many API components from external websites and  I struggle a bit. I don't really know where to put the different bits of code. The closer I am no is this :</p>
  <p>in Bapi.svelte (component) :</p>
  <pre><code>&lt;script&gt;
  
      function getSomething() {
          fetch('getapi')
      }
  &lt;/script&gt;
  
  &lt;h1&gt;get something here&lt;/h1&gt;
  &lt;button on:click={getSomething}&gt;Get !&lt;/button&gt;
  </code></pre>
  <p>in server.js (routes) :</p>
  <pre><code>import sirv from 'sirv';
  import express from 'express';
  import compression from 'compression';
  import * as sapper from '@sapper/server';
  
  const { PORT, NODE_ENV } = process.env;
  const dev = NODE_ENV === 'development';
  
  const app = express();
  
  app.use(express.urlencoded())
  app.use(express.json())
  
      app.use(
          compression({ threshold: 0 }),
          sirv('static', { dev }),
          sapper.middleware()
      )
      .listen(PORT, err =&gt; {
          if (err) console.log('error', err);
  });
  </code></pre>
  <p>in getapi.js (routes) :</p>
  <pre><code>export function get(res, req, next) {
      var resp = app.endpoints.coinbasepro.get('/coinbase-products');
      console.log(resp)
  }
  </code></pre>
  <p>When I click on get i have this error : app is not defined. I maybe has something to do with the scope but after moving the variable around for a while I need some help because I am stuck at this point. Thanks</p>