Group Group Group Group Group Group Group Group Group

How and when to use DELETE rest API, create in "Creating Controller" Chapter - 6

Hi, Can any one specify, when and how to use the DELETE rest api created under the topic “Creating Controller” chapter - 6.

thanks.

Can you be more specific on your question? DELETE is the method type you would send when you want to remove a token from the database. How you do it depends entirely on what your client is. From the command line, for example, you’d use curl. In a node application you’d make an ajax call, etc…

Hi,
So my question is that what are the scenarios under which I can make a DELETE call from the app.

Like if PushNotification token changes then should I make DELETE call first and if yes then what will be the token that I have pass as a parameter?

I am bit confused here so I hope my question make sense.

Thanks.

When you send a push, and APNs returns an error stating that the token is not valid any longer, then you’d DELETE that token.

As to your second question, no, do not try to capture token changes. Please look at the second to last page of the chapter at the section titled “But they disabled push!”

Ok so the DELETE call will always be made by the provider(i.e. when APNS returns an error for a token) and not by the application , right?

No. You, as the writer of the code that sends a push request to APNs, have to examine the response code from Apple. If the error is that the token isn’t valid, then you contact your API to remove that token.

So what I understood here is that iOS application register and receives a token from APNS which it then sends to

the server/provider to store.

Later server/provider uses stored token/tokens to send push notification request to APNS.

APNS could have following two responses

  1. Success - Notification gets delivered to respective device/devices.

  2. Error(token isn’t valid) - Server/provider makes a DELETE request to remove that token from DB.

Similar to what I found in “sendPushes.php” file, method - “sendNotifications($debug)” - Step 3

    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($code === 400 || $code === 410) {
        $json = @json_decode($response);
        if ($json->reason === 'BadDeviceToken') {
            $removeToken->execute([$token]);
        }}

Roughly this is what happens, right?

Thanks.

Yup, you’ve got it now.

Finally :sweat_smile:, thanks a lot for all the clarification.