Ionic 3: No response on REST API call

ionic 4 api call
calling api in ionic
ionic 3 api
ajax call in ionic 3
how to call api in ionic 1
ionic 4 http post request
ionic backend api
ionic 3 http get json

here's my issue:

I have this endpoint (GET) which gives me a JSON object as a result: 'localhost:3305/v1/patients' I use Ionic 3 with the provider 'RestProvider'. My rest.js looks like this:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';

@Injectable()
export class RestProvider {
    apiUrl = 'localhost:3305/v1';
    constructor(public http: HttpClient) {
        console.log('Hello RestProvider Provider');
    }

    getPatients() {
        return new Promise(resolve => {
            this.http.get(this.apiUrl+'/patients').subscribe(data => {
                resolve(data);
                console.log(data);
            }, err => {
                console.log(err);
            });
        });
    }
}

home.ts:

import { Component } from '@angular/core';
import { RestProvider } from '../../providers/rest/rest';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {
    patients: any;
  constructor (public restProvider: RestProvider) {
     this.getPatients();
    }

    getPatients() {
        this.restProvider.getPatients()
        .then(data => {
            this.patients = data;
            console.log(this.patients);
        });
    }
}

home.html:

<ion-content>
  <ion-navbar>
    <ion-title>My patients</ion-title>
  </ion-navbar>
  <ion-list>
    <ion-list-header>My patients</ion-list-header>
  </ion-list> 
  <ion-list inset>
    <ion-item *ngFor="let patient of patients">
      <p>{{patient}}</p>
    </ion-item>
  </ion-list>
</ion-content>

Problem: There's no error, but there's nothing shown in the view. console.log(data); of rest.js shows: [object Object].

Does anyone know where the mistake is? Thanks in regard!

Need to rewrite getPatients() code in following way:

getPatients() {
    return this.http.get(this.apiUrl+'/patients', {
      headers: new HttpHeaders().set('Content-Type', 'application/json'),
    })
   .toPromise()
}

And Getting data in home.ts

getPatients() {
    this.restProvider.getPatients().then((res => { 
        this.patients = data;
    }, (err) => {
       console.log("rejected"); 
    })
}

json - Ionic 3: No response on REST API call, here's my issue: I have this endpoint (GET) which gives me a JSON object as a result: 'localhost:3305/v1/patients' I use Ionic 3 with the provider  You must also already have Ionic 2 set up on your machine. If you’re not familiar with Ionic 2 already, I’d recommend reading my [Ionic 2 Beginners Guide][2] first to get up and running and understand the basic concepts. If you want a much more detailed guide for learning Ionic 2, then take a look at [Building Mobile Apps with Ionic 2][3]. 1.

Since you are using modern Angular you should use http methods in accordance with docs:

In your service:

getPatients() {
            return this.http.get(this.apiUrl+'/patients')
}

In your component:

getPatients() {
        this.restProvider.getPatients()
        .subscribe(data => {
            this.patients = data;
            console.log(this.patients);
        });
    }

Basically leverage observables as pointed out in comments

Ionic call rest service no catch http response code 401 on IOS, Ionic call rest service no catch http response code 401 on IOS Summarizing the call of the APi is made by IOS but when the error in the subscribe does Or do you have any suggestions? 3 Likes. seeyoucloud January 30, 2018, 2:56am #2. Ionic is flashing green on the back; but the screen won’t work & won’t sync. I tried restarting, no response. When I attach charger, the screen doesn’t show anything.

Don't forget to parse te response from the json, like this way, or the way you prefer.

getPatients() {
    return new Promise((resolve, reject) => {
        this.http.get(`${this.apiUrl}/patients`).subscribe(data => {
            try {
               response = response.json();
               resolve(response);
            } catch (error) {
               console.log('[api-153]', response);
               reject(response);
            }
            console.log(data);
            resolve(data);
        }, err => {
            console.log(err);
        });
    });
}

Calling an API or Making HTTP Requests in IONIC, Let's learn calling backend APIs in IONIC. Let's start by creating an app with the blank template, using ionic-start. ionic start HTTPapp blank — v2 –ts Not all APIs return this data. Some may return a different status code, some XML data, or nothing at all. Consult the documentation for your API to determine what the response format will look like. Possible bug in Firefox. At the time of this writing, the API calls on one of my projects were failing when run in Firefox.

Ionic 5/Angular, We'll cover how to create an Ionic 3 (2+) mobile app which makes use of HTTP module and RxJS library. We are not going to reinvent the wheel by building a REST API server but instead we are going to use Calling the Rest API import {HttpClient ,Response } from '@angular/common/http'; import  The REST service sends an HTTP status code in the HttpResponseMessage.IsSuccessStatusCode property, to indicate whether the HTTP request succeeded or failed. The common responses for this operation are: 204 (NO CONTENT) – the request has been successfully processed and the response is intentionally blank.

Ionic 5 HTTP POST with Angular by Example, How to use HttpClient to make example HTTP Post Requests in Ionic 5. In the previous tutorial, we've seen what's a REST API and RxJS. We also configured our Ionic 5/Angular is considered the next version of Ionic 3. Step 2 — Creating an Example REST API Server for our Angular 9 Application. In this tutorial, we don't need to create a real-world REST API instead we'll use json-server which allows us to quickly create a fake RESTful server and expose fake API endpoints, from sample data in a JSON file.

Error response external api · Issue #890 · ionic-team/capacitor · GitHub, It's not a CORS issue because I'm trying to consume my REST APIs located in an My API is in laravel, i use the same post method on Ionic 3 with the same API and It works. same. can't make api request work on android. A 307 response indicates that the REST API is not going to process the client’s request. Instead, the client should resubmit the request to the URI specified by the response message’s Location header. However, future requests should still use the original URI.

Comments
  • Dows it return any data when you try in postman or curl?
  • yes, the endpoint works fine. I already tested it via Postman.
  • You should not have to use Promises in Angular as HttpClient uses observables. Try removing the promise funcion