2
I need to check if the api is active. Basically I’m trying to check if the request status is 0; if so, I know the api is out of order.
But I wanted to put this method in my service class and only return true or false to whoever is going to use it, without having to call a subscrible and do the checks.
verificarServer(): Observable<boolean> {
return this.http.get('http://' + this.HOST + ':' + this.PORT + '/' + this.API).subscribe(
s => { },
e => {
if(e.status == 0){
}else{
}
}
);
}
That’s a code I’m trying to give you, but it would be something else at least as soon as I needed it. Something that returns me true or false in an observable.
How could I fix this ?
Edit1
The code using the map does not work (example of this reply)
I’m using the http of HttpClient
this.http.get('http://' + this.HOST + ':' + this.PORT + '/' + this.API).map((response:Response)=>{
console.log("imprime alguma coisa aqui Cara#$*&¨#*");
console.log(response.status);
});
does not fall within the function map
I think maybe this resolution will help you: https://stackoverflow.com/a/43683143/7857065
– Emerson Vieira
Thanks, but it didn’t work no, I’m using Httpclient, I think what’s in this answer is Http. Some methods that are in the answer do not even exist for Httpclient. I put the map in the get request to test, apparently I didn’t even fall into the map.
– Jeterson Miranda Gomes
You can return using
get<boolean>(url)
– Macario1983