PHPackages                             threedgroup/craft-rest-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. threedgroup/craft-rest-api

ActiveCraft-plugin[API Development](/categories/api)

threedgroup/craft-rest-api
==========================

Add REST features to craft

09PHP

Since Jan 14Pushed 7y ago2 watchersCompare

[ Source](https://github.com/3dgroup/craftrest)[ Packagist](https://packagist.org/packages/threedgroup/craft-rest-api)[ RSS](/packages/threedgroup-craft-rest-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)DependenciesVersions (2)Used By (0)

Craft REST API plugin for Craft CMS 3.x
=======================================

[](#craft-rest-api-plugin-for-craft-cms-3x)

- Add's Craft REST API
- Works with standard entries
- Config file gives ability to get custom elements
- Ability to add custom search within the prepareDataProvider option
- Removes some Craft specific endpoints that are not required (cp) As
- Uses Yii2 REST features.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require threedgroup/craft-rest-api

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft REST API.

Craft REST API Overview
-----------------------

[](#craft-rest-api-overview)

Gives a headles entry to craft CMS

Configuring Craft REST API
--------------------------

[](#configuring-craft-rest-api)

1. Create a new endpoint for craft by creating a new web directory called api. (In your route crate a new folder called api, that will sit next to the web folder). Then copy everything from the web folder into the api folder (cpresources not required).
2. inside the index.php file add the following lines under the existing constants:

```
define('REST', true);
```

Then in your app.php config file should look like below:

```
$config = [
    /** all exisintg config  EG: */
    'modules' => [
        'my-module' => \modules\Module::class,
    ]
];

if(!defined('REST')) {
    return $config;
}

return \craft\helpers\ArrayHelper::merge($config,
    require(CRAFT_VENDOR_PATH . '/threedgroup/craft-rest-api/src/config/rest.php'));
```

3. Create craft-rest-api.php settings file in your projects config folder

```
return [
    'sections' => [
        'testEntry' => [
            'fields' => [
                'id'
            ],
            'extraFields' => [
                'test'
            ],
            'prepareDataProvider' => function($model) {
                /** @var $query \craft\elements\Entry */
                $query = $model::find();

                return new \yii\data\ActiveDataProvider([
                    'query' => $query,
                ]);
            }
        ]
    ],
    'customElements' => [
        'question' => [
            'class' => \threedgroup\geekeyaftercare\elements\Question::class,
            /* fields removed the fields option is not used */
            'removeFields' => [
                '_statusData'
            ],
            /* Fields that will be displayed on the query */
            'fields' => [
                'id',
                'comment'=>function($model){
                    return (string) $model->comment;
                },
                'sku' => function($model){
                    $data=[];
                    foreach($model->skunew AS $variant){
                        $data[$variant->id] = $variant->sku;
                    }
                    return $data;
                }
            ],
            /* Required for saving data without these the custom fields will not be sent on the element */
            'customElementFields' => [
                'questionStatus' => 'questionStatus'
            ],
            /* Expandable fields for relations */
            'extraFields' => [
                'products'=> 'skunew'
            ],
            /* Ability to change the data provider of the query */
            'prepareDataProvider' => function($model) {
                /** @var $query Question */
                $query = $model::find();

                $productVariant = isset(\Yii::$app->request->queryParams['productVariant']) ? \Yii::$app->request->queryParams['productVariant'] : null;
                $searchString = isset(\Yii::$app->request->queryParams['search']) ? \Yii::$app->request->queryParams['search'] : null;

                if($productVariant) {
                    $query->productVariant($productVariant);
                }

                if($searchString) {
                    $query->search($searchString);
                }

                $query->with('SKUnew');

                return new \yii\data\ActiveDataProvider([
                    'query' => $query,
                ]);
            }
        ]
    ]
];
```

Using Craft REST API
--------------------

[](#using-craft-rest-api)

Use REST Application to test you data.

Craft REST API Roadmap
----------------------

[](#craft-rest-api-roadmap)

Some things to do, and ideas for potential features:

- Add token model so that system can login via token in REST request.

Brought to you by [3D Group](https://github.com/3dgroup)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3373fdbd202e814810361bba6fd04648b1d931ff423a1da04ff91441513bbc50?d=identicon)[threedgroup](/maintainers/threedgroup)

---

Top Contributors

[![3dgroup](https://avatars.githubusercontent.com/u/3091597?v=4)](https://github.com/3dgroup "3dgroup (9 commits)")

### Embed Badge

![Health badge](/badges/threedgroup-craft-rest-api/health.svg)

```
[![Health](https://phpackages.com/badges/threedgroup-craft-rest-api/health.svg)](https://phpackages.com/packages/threedgroup-craft-rest-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
