title: How to send POST and GET requests from Sails app to outside Sails API
body: <p>I am beginning to use SailsJS and i found it wonderful and powerful.</p>
  
  <p>Can anybody please explain me how to send POST and GET requests to an API outside Sails and where do i actually write this request?</p>
  
  <p>Thanks a lot and Happy 2016 everyone!!!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Hello @arcseldon, thank you for been trying to help me.</p>
  
  <p>I'll try to explain myself better, and show you my code.</p>
  
  <p>I have an API, written in php (which i think is not relevant) which accepts POST, GET, PUT, DELETE methods. I use Postman for testings and everything looks OK.</p>
  
  <p>I am trying to make an app in Sails, which GETs and POSTs requests to my API, but i dont know where is the best place to put the GET's and POST's codes.</p>
  
  <p>In the model i already have the following to ask for a token to perform the other requests, and it works:</p>
  
  <pre><code>gettoken: function (requestnewtoken,tokenresult) {
      if(!requestnewtoken) {
        tokenresult(global.tokeng);
      } else {
          request({
              headers: {
                  'User-agent' : 'develop',
                  'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8',
                  'Content-Length' : '29',
                  'Authorization' : 'Basic ' + global.idsecret
              },
              uri: "https://myapi/oauth2/token",
              method: "POST",
              form: {
                  grant_type: "client_credentials"
              }
          }, function(error, response, body) {
          var tokenjson = JSON.parse(body);
          var token = tokenjson['access_token'];
          global.tokeng = token;
              tokenresult(token);
          });
      }
  }
  </code></pre>
  
  <p>Then, i perform a GET request to another endpoint, which works:</p>
  
  <pre><code>listpublicroutes: function(requestnewtoken,cb) {
      Model.gettoken(requestnewtoken,function(token) {
          request({
              headers: {
                  'Authorization' : 'Bearer ' + token
              },
              uri: "https://myapi/folder/file.json",
              method: "GET",
              timeout: 10000,
              followRedirect: true,
              maxRedirects: 10
          }, function(error,response, body) {
          if(error || (response.statusCode != 200)) {
            Model.listpublicroutes(true,cb);
          } else {
                  cb(null,JSON.parse(body));
          }
          });
      });
  }
  </code></pre>
  
  <p>My doubts are if this is the best way to write a POST and GET request or they could be more simple, and if the requests should be done in the controller (or anywhere else) instead of the model.</p>
  
  <p>Can you give me an example of a POST and GET request?</p>
  
  <p>Thanks a lot to everyone who's trying to understand me.</p>