Vastlik
Vastlik

Reputation: 118

PHP waiting for API response

I am facing problem with API. I have my API, iOs app and foreign API.

iOs makes request on my API, my API makes request to foreign API. But now I have to wait for foreign API to send data to my callback which takes some time, for example 30 sec. How should I keep conenction with iOs app?

I have 3 possible solutions.

  1. Ask my API for example every 10 sec. if data already arrived.
  2. Send notifications to my app when data arrive.
  3. Create socket which will listen for response, if I understand sockets correctly.

Is there any other solution? Or what is the best practice?

Upvotes: 1

Views: 299

Answers (1)

Igor
Igor

Reputation: 2919

Another approach you could try is using APN for notifying the app about new data arrivals.

  1. The iOS client makes a request to your API

  2. Your API makes a request to the ext. API, returns a response to the iOS client

  3. Once the data from the ext. API arrives, your API sends a push notification to the iOS client, notifying the latter that the data is ready to be picked up
  4. iOS client receives the push notification (PN), does not show the PN to the user (human)
  5. iOS client makes another request to retrieve the data.

Upvotes: 1

Related Questions