I’m building an application where users can log in with their GitHub account. After authentication, I show them their current followers and want to add an unfollow feature. I found the GitHub API endpoint I need to use:
DELETE /user/following/:username
But I’m stuck on how to implement this DELETE request in PHP. Can someone show me the proper way to send this type of request?
Also having issues with errors showing up when users refresh the page. Any suggestions on handling that would be great too.
For DELETE requests with GitHub’s API, cURL works best. Set the method to DELETE and include your auth token in the headers. Use curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘DELETE’) and don’t forget the User-Agent header - GitHub requires it. Getting errors on page refresh? Try the POST-redirect-GET pattern to prevent duplicate submissions after DELETE. Always check the response status code before telling the user the unfollow worked.
I’ve done something similar and Guzzle HTTP client makes DELETE requests way cleaner than raw cURL. Just composer install guzzlehttp/guzzle, set up a client with your OAuth token and User-Agent in the base headers, then call $client->delete(‘/user/following/’ . $username). Response handling is simple with status code checks. For the refresh problem, I store the action result in session and clear it after showing - stops repeated API calls when people hit F5. Watch out for GitHub’s rate limiting though. Users spamming the unfollow button will hit limits fast, so add some client-side debouncing.