Search code examples
angularionic-frameworkangular-httpclient

ionic 3 HttpClient get status + send headers


i'm using the HttpClientModule on ionic 3, and i want to do a get on my api

let email = "test@email.com";
let password = "password";
    let headers = new HttpHeaders();
    this.http.get('http://127.0.0.1:8000/api/login',{
      headers: {'email':email,'password':password}
   });

i don't want to get the json but only the status of the request, for doing something like :

if(status == 200) { ... }
esle { ... } 

can you guys please help me ?

Thank you


Solution

  • Add observe : 'response' in header options of http.get method and subscribe to get() method to get response status whatever you want..

    this.http.get('http://127.0.0.1:8000/api/login',{
          headers: {'email':email,'password':password},observe: 'response'
       }).subscribe(
        res => { console.log(res) ;
    
                 if(res.status==201)
                 {
                     //do action
                 }else
                 {
                 }
              },