Body: <p>I want to make a Restful API with JWT in order to be able to make calls to it. </p>
  
  <p>I have this in <code>/config/app.php</code>:</p>
  
  <pre><code>return [
      'modules' =&gt; [
          'my-module' =&gt; \modules\Module::class,
          'demarketsjwt' =&gt; \demarkets\Module::class,
      ],
      // 'bootstrap' =&gt; ['demarketsjwt'],
      'components' =&gt; [
          'listingsDb' =&gt; [
              'class' =&gt; craft\db\Connection::class,
              'driverName' =&gt; 'mysql',
              'dsn' =&gt; 'mysql:host=localhost;dbname=' . getenv('DB_LISTINGS_DBNAME') . ';port=' . getenv('DB_LISTINGS_DBPORT') . ';',
              'username' =&gt; getenv('DB_LISTINGS_USER'),
              'password' =&gt; getenv('DB_LISTINGS_PASSWORD'),
              'charset' =&gt; 'utf8',
              'tablePrefix' =&gt; '',
              'enableSchemaCache' =&gt; !YII_DEBUG,
          ],
          'urlManager' =&gt; [
              'enablePrettyUrl' =&gt; true,
              'enableStrictParsing' =&gt; true,
              'showScriptName' =&gt; false,
              'rules' =&gt; [
                  ['class' =&gt; 'craft\web\UrlRule', 'controller' =&gt; 'user'],
              ],
          ],
      ],
  ];
  </code></pre>
  
  <p>and I have this in <code>/controllers/UserController.php</code>:</p>
  
  <pre><code>&lt;?php
  
  namespace app\controllers;
  
  use Craft;
  use craft\web\ActiveController;
  
  class UserController extends ActiveController
  {
      // public $modelClass = 'app\models\User';ç
      public function init()
      {
          parent::init();
          $now = time();
          $rows = Craft::$app-&gt;listingsDb-&gt;createCommand("SELECT * FROM table;")-&gt;execute();
          echo $rows;
      }
  }
  </code></pre>
  
  <p>I am doing tests with Postman app but I cannot make it work. What am I doing wrong?</p>
  
  <p>Thank you in advance for your kind help.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T12:49:48.340Z
Comments.Text: Anyone please? I need help.
Comments.UserDisplayName: Rafael Mora
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T16:39:54.530Z
Comments.Text: From a quick glance, you might need to disable CSRF routing on that controller.  You can disable per controller by setting a public property of  `$enableCsrfValidation` to false.
  
  You can also disable it globally (https://docs.craftcms.com/v3/config/config-settings.html#enablecsrfprotection) but I would recommend only disabling it when necessary to maintain better security on your installation.
Comments.UserDisplayName: Jason McCallister
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T16:57:50.733Z
Comments.Text: Ok I will do that and get back to you. Thanks!
Comments.UserDisplayName: Rafael Mora
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-26T23:01:48.517Z
Comments.Text: @JasonMcCallister I tried what you suggest but I keep getting `"error": "Template not found: users"` What do you suggest? Where should the controller be placed? how should the controller be named? Thank you.
Comments.UserDisplayName: Rafael Mora
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-27T00:52:20.817Z
Comments.Text: Sounds like its looking for the web, not API request. Try setting the Accept header on Postman to be application/json. I have this example module working as an API request: https://github.com/jasonmccallister/craft-console/blob/master/src/controllers/ApiController.php
Comments.UserDisplayName: Jason McCallister
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-28T10:53:22.707Z
Comments.Text: I'm using the header `application/json` and I've seen your example but still getting `{
      "error": "Template not found: api/users"
  }`
Comments.UserDisplayName: Rafael Mora
Tags: <craft3>
Title: Restful API using Craft 3 with JWT
ThreadText: # Restful API using Craft 3 with JWT
  
  (Asked by: username_0 on 2019-10-24)
  
  I want to make a Restful API with JWT in order to be able to make calls to it.
  
  I have this in `/config/app.php`:
  
  ```
  return [
      'modules' => [
          'my-module' => \modules\Module::class,
          'demarketsjwt' => \demarkets\Module::class,
      ],
      // 'bootstrap' => ['demarketsjwt'],
      'components' => [
          'listingsDb' => [
              'class' => craft\db\Connection::class,
              'driverName' => 'mysql',
              'dsn' => 'mysql:host=localhost;dbname=' . getenv('DB_LISTINGS_DBNAME') . ';port=' . getenv('DB_LISTINGS_DBPORT') . ';',
              'username' => getenv('DB_LISTINGS_USER'),
              'password' => getenv('DB_LISTINGS_PASSWORD'),
              'charset' => 'utf8',
              'tablePrefix' => '',
              'enableSchemaCache' => !YII_DEBUG,
          ],
          'urlManager' => [
              'enablePrettyUrl' => true,
              'enableStrictParsing' => true,
              'showScriptName' => false,
              'rules' => [
                  ['class' => 'craft\web\UrlRule', 'controller' => 'user'],
              ],
          ],
      ],
  ];
  
  ```
  
  and I have this in `/controllers/UserController.php`:
  
  ```
  <?php
  
  namespace app\controllers;
  
  use Craft;
  use craft\web\ActiveController;
  
  class UserController extends ActiveController
  {
      // public $modelClass = 'app\models\User';ç
      public function init()
      {
          parent::init();
          $now = time();
          $rows = Craft::$app->listingsDb->createCommand("SELECT * FROM table;")->execute();
          echo $rows;
      }
  }
  
  ```
  
  I am doing tests with Postman app but I cannot make it work. What am I doing wrong?
  
  Thank you in advance for your kind help.
  
  **Tags:** craft3
  
  > **Comments:**
  > **username_0**: Anyone please? I need help.  
  > **username_1**: From a quick glance, you might need to disable CSRF routing on that controller.  You can disable per controller by setting a public property of  `$enableCsrfValidation` to false.  You can also disable it globally (https://docs.craftcms.com/v3/config/config-settings.html#enablecsrfprotection) but I would recommend only disabling it when necessary to maintain better security on your installation.  
  > **username_0**: Ok I will do that and get back to you. Thanks!  
  > **username_0**: @username_1 I tried what you suggest but I keep getting `"error": "Template not found: users"` What do you suggest? Where should the controller be placed? how should the controller be named? Thank you.  
  > **username_1**: Sounds like its looking for the web, not API request. Try setting the Accept header on Postman to be application/json. I have this example module working as an API request: https://github.com/username_1/craft-console/blob/master/src/controllers/ApiController.php  
  > **username_0**: I'm using the header `application/json` and I've seen your example but still getting `{     "error": "Template not found: api/users" }`  
  
  ---
  
  ## 0 answers
  
  