Grapic dots

Debugging with Postman and PHPStorm (Xdebug)

Mike Milano

Postman started out as an API development tool, but has developed more into, as they put it, an “API Development Environment”.

An over-simplified description is it allows you to create and save requests to test your API. You can then save your requests as a collection and share or publish them for others to use.

It supports API calls for all request types, fine control over headers, common authentication methods, and long list of other features that could fill an article… but I wanted to write specifically about using Xdebug with Postman.

How to trigger Xdebug when working with Postman

Recently, I was using Postman to troubleshoot an API Platform project and needed to trigger a Xdebug session in my IDE, PhpStorm.

Typically, I rely on a browser extension to trigger Xdebug, however Postman is its own application, so I could not rely on browser extensions.

Fortunately, there’s an easy solution: Add XDEBUG_SESSION_START=PHPSTORM to the query string and PHPStorm will catch the debug session as it would if you were using a browser extension.

For example, if you are working on http://localhost:8000/api/users, simply append the URL with the query string mentioned above to initiate a debug session:

http://localhost:8000/apiusers?XDEBUG_SESSION_START=PHPSTORM

Now you can set breakpoints and debug as you would if you were working in a browser.

8 Reasons Why Standardizing on Drupal is the Right Choice for Enterprise.
Read about it in this free white paper.

Download for Free Now!