PHP Classes

How to Develop a PHP JSON:API Server In Less Time Using the Package Yii2 Fractal: Components to implement API based on JSON:API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-09-26 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 11 All time: 11,485 This week: 51Up
Version License PHP version Categories
yii2-fractal 1.0MIT/X Consortium ...5PHP 5, Libraries, Web services, Desig...
Description 

Author

This package provides components to implement API based on JSON:API.

It provides classes and traits API developers can use to implement PHP-based APIs that implement the JSON:API specification.

Currently it provides classes and traits to implement action controllers, data providers, and data pagination.

Innovation Award
PHP Programming Innovation award nominee
September 2024
Number 6
JSON:API is a specification used to design web services APIs using the JSON format to send requests and return responses.

This package provides many useful components to develop APIs based on JSON:API specification, thus reducing the effort to implement this kind of API.

Manuel Lemos
Picture of Insolita
  Performance   Level  
Innovation award
Innovation award
Nominee: 18x

 

Example

<?php

defined
('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');

require
dirname(__DIR__, 3) . '/vendor/autoload.php';
require
dirname(__DIR__, 3) . '/vendor/yiisoft/yii2/Yii.php';

$config = require dirname(__DIR__) . '/config/api.php';

(new
yii\web\Application($config))->run();


Details

yii2-fractal Beta

yii2-fractal

The set of utils and actions for prepare Rest API accordingly JSON:Api https://jsonapi.org/format/ With https://fractal.thephpleague.com

Installation

composer require insolita/yii2-fractal

Usage

  1. Add class `insolita\fractal\JsonApiBootstrap` to the ['bootstrap' section] of api application config (or update application config manually with same changes as in `JsonApiBootstrap` class ) see tests/testapp/config/api.php.
  2. Create your controller classes by extending `JsonApiController` or `JsonApiActiveController` which contains predefined CRUD actions. See examples at tests/testapp/controllers.

['bootstrap' section]: https://www.yiiframework.com/doc/guide/2.0/en/runtime-bootstrapping

### Testing

- Clone project - Run make up - Run once make installdocker - Run make testdocker or make cli and inside docker env make test


  Files folder image Files (94)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (9 files, 4 directories)
Files folder imagetests (4 directories)
Accessible without login Plain text file .dockerignore Data Auxiliary data
Accessible without login Plain text file .php_cs.dist Example Example script
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:11
This week:0
All time:11,485
This week:51Up