Skip to content
Manages and generates RESTful APIs
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
actions
classes Use laravel eloquent resource instead of league’s fractal Apr 23, 2019
config Change form toolbar button data attribute to submit form instead of u… Dec 16, 2018
console Use laravel eloquent resource instead of league’s fractal Apr 23, 2019
controllers
database/migrations
exception Fix minor issues Oct 18, 2018
models Use laravel eloquent resource instead of league’s fractal Apr 23, 2019
views/resources First commit Oct 14, 2018
Extension.php Use laravel eloquent resource instead of league’s fractal Apr 23, 2019
LICENSE Update copyright Feb 1, 2019
README.md
extension.json
routes.php Use laravel eloquent resource instead of league’s fractal Apr 23, 2019

README.md

APIs is an extension that allows you to build RESTful APIs and manage them within a TastyIgniter application.

However, it accomplishes more than just that, you may override the api actions (verbs) with your own logic. Default behavior logic for several common verbs are supported — create, store, show, edit, update, destroy.

Features

  • Auto Generate Controller (CRUD)
  • Auto Generate Resource Response Class (For modeling JSON response)
  • Support relationships

TO DO:

  • User Authentication (with Laravel Passport)
  • Generating User Tokens

Usage

In the admin user interface, go to Tools > APIs and use the Create button to generate a new api resource

Manually Create an API resource

The below command will generate both Controller and Resource Transformer for the specified resource

php artisan create:apiresource Acme.Extension ResourceName

After the resource has been generated, add it to routes by registering a new api resource.

Register API Resource

public function registerApiResources()
{
    return [
        'menus' => [
            'name' => 'Menus',
            'description' => 'Description of this API resource',
            'controller' => \Acme\Extension\Resources\Menus::class,
            'transformer' => \Acme\Extension\Resources\Transformers\MenuTransformer::class,
        ],
    ];
}

The array keys represents the resource endpoints

Resource Transformer

Response are transformed using laravel's eloquent resources.

Example of Resource Transformer

<?php namespace Igniter\Api\Resources\Transformers;

use Illuminate\Http\Resources\Json\Resource;

class MenuTransformer extends Resource
{
	public function toArray($request)
	{
	    return [
	        'id'      => (int) $this->menu_id,
	        'name'    => $this->menu_name,
            'links'   => [
                [
                    'rel' => 'self',
                    'uri' => '/api/menus/'.$this->menu_id,
                ]
            ],
	    ];
	}
}
You can’t perform that action at this time.