title: How do you protect a restful api endpoint in flutter
body: <p>I have a flutter mobile app that call a backend API server. This requires an API key . I don't want to embed the key into the app . How do I protect the API key and the endpoint for unauthorized access. My app does not not required the user to login.</p>
  <p>The only idea that I can come up with is to have a pass-thru (nodejs ) server that makes the call to the API server and I can store the key on that server so it is not in the app</p>
  <p>However, now I will need to protect the node server.</p>
  <p>Any suggestion on how to do this or do you have a better solution.</p>
  <p>Thanks for your suggestion</p>
  <p>Example</p>
  <pre><code>class UserService {
    Future&lt;List&lt;users&gt;&gt; getUser() async {
      var response =
          await http.get(Uri.parse(user));
      final int statusCode = response.statusCode;
      User uData = json.decode(response.body);
      return uData
    }
  }
  </code></pre>
  <p><strong>App.js</strong></p>
  <pre><code>var express = require('express');
  var app = express();
  var PORT = process.env.PORT || 3000;
  
  app.get('/user', function(req, res) {
    res.json({
      &quot;employees&quot;: [
        { &quot;firstName&quot;:&quot;John&quot;  , &quot;lastName&quot;:&quot;Doe&quot;   },
        { &quot;firstName&quot;:&quot;Anna&quot;  , &quot;lastName&quot;:&quot;Smith&quot; },
        { &quot;firstName&quot;:&quot;Peter&quot; , &quot;lastName&quot;:&quot;Jones&quot; }
      ]
    })
  });
  
  app.listen(PORT);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/fyAvT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fyAvT.png" alt="enter image description here" /></a></p>