title: How to consume Login Service from UI Service in Spring Boot?
body: <p>I have 2 microservices, 1 is having all UI and 1 is having Login Solution connected with MySQL Database. </p>
  
  <p>I have tried Login and UI working in same services.</p>
  
  <pre><code>@RequestMapping("/accounts/login") //login 
  public String login(HttpServletRequest request) {
      request.setAttribute("mode", "MODE_LOGIN");
      return "login";
  }
  
  @RequestMapping ("/login-user") // checking user details in database
  public String loginUser(@ModelAttribute User user, HttpServletRequest request) {
      //ModelAndView model = new ModelAndView();
      if(userService.findByEmailAndPassword(user.getEmail(), user.getPassword())!=null) {
          return user.getFirstname();
  
      }
      else {
          request.setAttribute("error", "Invalid username and password!");
          request.setAttribute("mode", "MODE_LOGIN");
          return "login";
      }
  }
  </code></pre>
  
  <p>This is my code for Login, and in JSP i have put like</p>
  
  <pre><code> &lt;c:choose&gt;
      &lt;c:when test="${mode=='MODE_HOME' }"&gt; //some code after this
    &lt;c:when test="${mode=='MODE_LOGIN' }"&gt;    
     &lt;form action="/login-user" method="POST"&gt; //form after this
  </code></pre>
  
  <p>This above one is done in 1 service only, but now i want UI should be separated and that UI should consume this Login Solution from there.</p>
  
  <p>My Understanding is: I have created same POJO in UI Microservice and Controller i am trying to consume login service in below given way</p>
  
  <pre><code>@RequestMapping("validate")
  private String login1()
  {
      final String uri = "http://localhost:8091/accounts/login";
  
      RestTemplate restTemplate = new RestTemplate();
      String result = restTemplate.getForObject(uri, String.class);
  
      return result;
  }
  </code></pre>
  
  <p>I am confused how will i call then @RequestMapping("/login-user") where the actual validation is happening. </p>
  
  <p>I am to new to this architecture. Any other way out here.</p>