Download the PHP package futureactivities/craft3-rest-api without Composer

On this page you can find all versions of the php package futureactivities/craft3-rest-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft3-rest-api

Craft REST API

The REST API plugin by FutureActivities provides easy to use API endpoints for any Craft 3 or 4 installation. No configuration required, just enable the plugin and the endpoints are immediately available.

You can optionally exclude certain fields and sections from the API to avoid exposing data.

Use v1 for Craft 3, v2+ for Craft 4.

Features

Installation

Install via composer:

composer require futureactivities/craft3-rest-api

Usage

Further documentation of available endpoints can be found at:

https://craftrest.docs.apiary.io/

Examples

Get all categories:

GET /rest/v1/categories

Get all categories with the related field expanded - this will return data objects instead of IDs.

GET /rest/v1/categories?expand=related

Get a specific category

GET /rest/v1/categories/18

Get all entries belonging to the news channel & limit results to slug and title only:

GET /rest/v1/entries?filter[section]=news&fields=slug,title

Get all entries in the news channel, expand featured image and apply a specific image transform:

GET /rest/v1/entries?filter[section]=news&expand=featuredImage&transforms[featuredImage]=featuredFull,featuredThumb

Settings

From the control panel the plugin can be configured with the following settings:

General

Include Disabled - Should disabled entries, categories, etc. be included in the API results.

Enable Assets - Enable the asset endpoints

Enable Tags - Enable the tag endpoints

Fields

Configure which custom fields are available in the API results.

Sections

Configure which sections are available in the API results.

Events

Field Event

This plugin only supports a limited number of field types in the API responses, for other field types and custom field types you can process the response yourself using the following event:

Event::on(\futureactivities\rest\services\Fields::class, \futureactivities\rest\services\Fields::EVENT_PROCESS_FIELD, function(Event $event) {
    $field = $event->field;

    if (is_a($field, 'namespace\plugin\CustomFieldType'))
        $event->data = [
            'key' => 'value'   
        ];
    }
});

Extra Fields Event

Sometimes you might want to include additional data in the response, the following event will allow you to add your own fields to the element.

Event::on(\futureactivities\rest\models\Element::class, \futureactivities\rest\models\Element::EVENT_EXTRA_FIELDS, function(Event $event) {
    $model = $event->model;

    if (is_a($model, 'craft\elements\Entry') && $model->section->handle == 'news') {
        $event->fields = [
            'myCustomField' => 'Hello'  
        ];
    }
});

Authentication

If you are using the user authentication functionality of this plugin, then you may need to configure your server to ensure the authorisation headers are passed to Craft. For Apache this is done by adding the following to your conf file:

RewriteEngine On
RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Cron

Expiring tokens

Out of the box, user authentication tokens will never expire. To expire tokens, setup a cron job running the following command:

./craft rest/token/expire <seconds>

<seconds> is optional. Default is 3600 seconds (1 hour).

Changelog

1.2

1.1

Roadmap

The following features are planned for future versions:


All versions of craft3-rest-api with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^4.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package futureactivities/craft3-rest-api contains the following files

Loading the files please wait ....