Home > Blockchain >  Unable to get Response from API in angular
Unable to get Response from API in angular

Time:02-26

I have created a Rest API in Java with the request Mapping(/value/generate).

System.out.println(value);
        
        
        if(!value.equals(null)){
         return new ResponseEntity(value, HttpStatus.OK);
        }
        return new ResponseEntity(HttpStatus.FORBIDDEN);
            
    }

Value is getting printed in Console when iam call this through postman.

But i need to print this value in my Angular console.

Below is code i have created in angular.

service.ts

generatevalue(): Observable<String> {
return this.http.get('https://localhost:8080/value/generate')

Component.ts

ngOnInit() {
     this.service.generatevalue().subscribe((Response) => {
      console.log(Response)
     
  }
 }

Please let me know where i went wrong.

CodePudding user response:

Your url should probably be "http://localhost:8080/value/generate". Did you check your console for errors? It should print an error 404 somewhere.

  • Related