I have the following code to consume a back-end API served by a Play application. The API http://localhost:9000/ws/users/get
works if I type it as is on the browser window (I see the response hello from get user controller
on the window and also a debug print `get user request in my play application) but the Angular code doesn't seem to send anything to the backend (I don't see any debugs at all in either play or browser's window).
Question 1 - How could I debug where Angular is sending the message Question 2 - why isn't the code working?
import { Injectable } from '@angular/core';
import { environment } from 'environments/environment';
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { HttpClient} from '@angular/common/http';
import {User} from "./user";
@Injectable()
export class WebToBackendInterfaceService {
API_URL = environment.apiUrl;
ADD_USER_URL = environment.addUserUrl;
GET_USER_URL = environment.getUserUrl;
constructor(private http:HttpClient) { }
public createUser(user:User):any{
console.log('contacting server at '+this.API_URL +this.ADD_USER_URL +" with user data ",user); //if I click this link directly fro browser's debug window then I see response from the server
this.http.post(this.API_URL +this.ADD_USER_URL,user)
.map(response => {
console.log('response from backend service',response);
return response;
})
.catch(this.handleError); //error handler if Observable fails
}
public getUser(id:string):any{
console.log('contacting server at '+this.API_URL +this.GET_USER_URL +" with user data "+id);
this.http.get(this.API_URL+this.GET_USER_URL)
.map(response=>{
console.log('response from backend service',response);
return response;
})
.catch(this.handleError);
}
private handleError (error: Response | any) {
console.error('WebToBackendInterfaceService::handleError', error);
return 'error from the server:'+error;
}
}