Implement REST API with Javascript


Hello! I’m currently using an online IDE to create a mobile app. I want the app to be able to authenticate users using REST API from an external database.

I’ve written the login form using HTML:

    <div class="center">Login</div>

  <div style="text-align: center; margin-top: 30px;">
      <ons-input id="username" modifier="underbar" placeholder="Username" float></ons-input>
      <ons-input id="password" modifier="underbar" type="password" placeholder="Password" float></ons-input>
    <p style="margin-top: 30px;">
      <ons-button onclick="login()">Sign in</ons-button>

To call to the Web API, I’m using Javascript:

var username = "Username";
  var password = "Password";
  function = login () {
      var request = new XMLHttpRequest ();"GET", "", false);
      request.setRequestHeader ("Authorization", "Bearer");

This is pretty much how far I’ve gotten. I’ve got a token endpoint and request endpoint, but I’m not quite sure how to use it yet. I also want to have error message in case the information a person has entered is incorrect.

Can I use if statements to implement error messages?

Thank you for the help!