<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Danny Rios Tolosa</title>
    <description>The latest articles on DEV Community by Danny Rios Tolosa (@danny_riostolosa_9233486).</description>
    <link>https://dev.to/danny_riostolosa_9233486</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4133776%2F86ac4c57-fd38-42c1-bf46-ffdd2ac35f4d.png</url>
      <title>DEV Community: Danny Rios Tolosa</title>
      <link>https://dev.to/danny_riostolosa_9233486</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danny_riostolosa_9233486"/>
    <language>en</language>
    <item>
      <title>Stop maintaining Postman collections by hand in Yii2</title>
      <dc:creator>Danny Rios Tolosa</dc:creator>
      <pubDate>Mon, 16 Nov 2026 21:29:36 +0000</pubDate>
      <link>https://dev.to/danny_riostolosa_9233486/stop-maintaining-postman-collections-by-hand-in-yii2-4e3k</link>
      <guid>https://dev.to/danny_riostolosa_9233486/stop-maintaining-postman-collections-by-hand-in-yii2-4e3k</guid>
      <description>&lt;p&gt;Every API team has the same file: a Postman collection that was correct six months ago. Someone adds an endpoint, nobody updates the collection, and the next person onboarding spends an afternoon guessing URLs and bodies.&lt;/p&gt;

&lt;p&gt;OpenAPI solves this, but for many internal Yii2 APIs a full spec is more than the team needs. What people actually use is a collection to click through.&lt;/p&gt;

&lt;p&gt;This post shows a smaller approach: describe each endpoint with a few annotations right next to the action, and generate the collection with one command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require --dev iguazoft/yii2-postman-generator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extension registers a &lt;code&gt;postman&lt;/code&gt; console command through Yii2's extension bootstrap. There is nothing to configure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Annotate an action
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @Postman\Collection("Shop API")
 * @Postman\BaseUrl("https://api.shop.test")
 */&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserController&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; \&lt;span class="n"&gt;yii&lt;/span&gt;\&lt;span class="n"&gt;rest&lt;/span&gt;\&lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/**
     * @Postman\Request("List users")
     * @Postman\Folder("Users")
     * @Postman\Path("/api/users")
     * @Postman\Query("page", "1")
     * @Postman\Auth("bearer", "{{token}}")
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;actionIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * @Postman\Request("Create user")
     * @Postman\Folder("Users")
     * @Postman\Method("POST")
     * @Postman\Path("/api/users")
     * @Postman\Body({
     *     "name": "John Doe",
     *     "email": "john@example.com"
     * })
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;actionCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only actions with &lt;code&gt;@Postman\Request&lt;/code&gt; are exported, so you can adopt it one endpoint at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php yii postman/generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command scans &lt;code&gt;@app/controllers&lt;/code&gt; (use &lt;code&gt;--dirs&lt;/code&gt; for modules) and writes &lt;code&gt;@app/docs/api.postman_collection.json&lt;/code&gt;. Import it in Postman with Import &amp;gt; File. The same file works in Insomnia, Bruno and Hoppscotch, which read the Postman v2.1 format.&lt;/p&gt;

&lt;p&gt;What you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Folders from &lt;code&gt;@Postman\Folder&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{{baseUrl}}&lt;/code&gt; and &lt;code&gt;{{token}}&lt;/code&gt; collection variables&lt;/li&gt;
&lt;li&gt;Query parameters, headers and JSON bodies&lt;/li&gt;
&lt;li&gt;Path variables: &lt;code&gt;/users/:id&lt;/code&gt; or &lt;code&gt;/users/{id}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Bearer, basic and API key auth&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keep it in sync with CI
&lt;/h2&gt;

&lt;p&gt;The collection id is derived from the collection name, so generating twice gives the same file. That means you can commit the JSON and fail the build when someone forgets to regenerate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php yii postman/generate&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;git diff --exit-code docs/api.postman_collection.json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A pull request that adds an annotated endpoint without regenerating the collection now fails the build.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use OpenAPI instead
&lt;/h2&gt;

&lt;p&gt;If you publish a public API, need response schemas, or generate client SDKs, use OpenAPI. This extension is for the common case where the team needs a working collection and nothing more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;The code is MIT, tested on PHP 7.4 to 8.4: &lt;a href="https://github.com/dannyrios81/yii2-postman-generator" rel="noopener noreferrer"&gt;https://github.com/dannyrios81/yii2-postman-generator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If something is missing for your API, open an issue. Reading routes from UrlManager rules is the next idea on the list.&lt;/p&gt;

</description>
      <category>php</category>
      <category>yii</category>
      <category>api</category>
      <category>postman</category>
    </item>
  </channel>
</rss>
