title: Angular Typescript send optional restful url params only if they are not empty
body: <p>Current system that I have control of is only the front end which is Angular 5 ( thus Typescript)  .  Backend should not matter, but there is a team in which they are not changing their signatures, their error handling etc..  :/  </p>
  
  <p>Issue is that there is a search screen in which only 1 field is required, so when I am trying to send a URL to a Restful backend ( actually as I type this.. this is not really restful, is it? )   </p>
  
  <p><strong>My Angular Service method:</strong></p>
  
  <pre><code>getSearchByUserResults(first,last,user,eff,term,emp) {
  
         //IF I JUST DO THIS, THEN EMPTY PARAMS ARE SENT AND SOMEHOW THE BACKEND IS NOT SET UP TO HANDLE THAT  :/ 
         //var params = "userid=" + user + "&amp;first-name=" + first + "&amp;last-name=" + last + "&amp;eff-date=" + eff + "&amp;term-date=" + term + "&amp;employee-id=" + emp;
  
      //Sending only userid works
      //var params = "userid=" + user;
  
      // Send user and first when first name is empty(null) again it does NOT work
      var params = "userid=" + user + "&amp;first-name=" + first;
  
  
  
      var searchUser = this._searchByUser + params;
  
  
      return this._http.get(searchUser).map((response: Response) =&gt; response.json()).catch(this.handleError);
  }
  </code></pre>
  
  <blockquote>
    <p>Basically what I am showing is in the comments above.   </p>
  </blockquote>
  
  <p>If a param is empty or null, then I DO NOT want it to be added to the list of params send to the server controller method... </p>
  
  <ol>
  <li>if user = 123  send  <a href="http://server.com:9080//rest/config/users?userid=123" rel="nofollow noreferrer">http://server.com:9080//rest/config/users?userid=123</a></li>
  <li>if user and first name not empty send  <a href="http://server.com:9080//rest/config/users?userid=123&amp;first-name=Ted" rel="nofollow noreferrer">http://server.com:9080//rest/config/users?userid=123&amp;first-name=Ted</a></li>
  <li>Never send something with empty params like this empty first-name   <a href="http://server.com:9080//rest/config/users?userid=123&amp;first-name=" rel="nofollow noreferrer">http://server.com:9080//rest/config/users?userid=123&amp;first-name=</a></li>
  </ol>
  
  <p>Based on that list of params, how can I do this without a bunch of if statements checking for null/empty/undefined  ?  </p>
  
  <p><code>first,last,user,eff,term,emp</code></p>