SR
Click to open github profile
Get Started

Installation

Learn how to install the Craft Query API Craft CMS plugin.


Craft CMS Setup

Set up a Craft CMS > 5 project. You could use that Guide.

Install

With ddev:

ddev composer require samuelreichor/craft-query-api &&
ddev craft plugin/install craft-query-api

With php:

composer require samuelreichor/craft-query-api &&
php craft plugin/install craft-query-api

Configure Cors Origins

Add following config in that file config/app.web.php to prevent cors origin errors in your frontend. You can find more information about that in the Craft Docs.

<?php

  return [
      'as corsFilter' => [
          'class' => \craft\filters\Cors::class,

          // Add your origins here
          'cors' => [
              'Origin' => [
                  'http://localhost:3000',
                  'http://localhost:5173',
              ],
              'Access-Control-Request-Method' => ['GET'],
              'Access-Control-Request-Headers' => ['*'],
              'Access-Control-Allow-Credentials' => true,
              'Access-Control-Max-Age' => 86400,
              'Access-Control-Expose-Headers' => [],
          ],
      ],
  ];

Finish

That's it you can test it by hitting that endpoint ${PRIMARY_SITE_URL}/v1/api/queryApi/customQuery. You should get an empty array as response.


Copyright © 2024 Samuel Reichör