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 (21 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
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.

Picture of Insolita
  Performance   Level  
Name: Insolita <contact>
Classes: 25 packages by
Country: Russian Federation Russian Federation
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

  Files folder image Files (94)  /  .github  
File Role Description
Files folder imageworkflows (2 files)

  Files folder image Files (94)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test.yml Data Auxiliary data
  Accessible without login Plain text file test_docker.yml Data Auxiliary data

  Files folder image Files (94)  /  src  
File Role Description
Files folder imageactions (18 files)
Files folder imageexceptions (2 files)
Files folder imagepagination (2 files)
Files folder imageproviders (5 files)
  Plain text file ActiveJsonApiController.php Class Class source
  Plain text file DefaultTransformer.php Class Class source
  Plain text file IdOnlyTransformer.php Class Class source
  Plain text file JsonApiBootstrap.php Class Class source
  Plain text file JsonApiController.php Class Class source
  Plain text file JsonApiError.php Class Class source
  Plain text file JsonApiErrorHandler.php Class Class source
  Plain text file JsonApiResponseFormatter.php Class Class source
  Plain text file RelationshipManager.php Class Class source

  Files folder image Files (94)  /  src  /  actions  
File Role Description
  Plain text file CountAction.php Class Class source
  Plain text file CountForIdentityAction.php Class Class source
  Plain text file CreateAction.php Class Class source
  Plain text file CreateRelationshipAction.php Class Class source
  Plain text file DeleteAction.php Class Class source
  Plain text file DeleteRelationshipAction.php Class Class source
  Plain text file HasIncludes.php Class Class source
  Plain text file HasParentAttributes.php Class Class source
  Plain text file HasResourceBodyParams.php Class Class source
  Plain text file HasResourceTransformer.php Class Class source
  Plain text file JsonApiAction.php Class Class source
  Plain text file ListAction.php Class Class source
  Plain text file ListForIdentityAction.php Class Class source
  Plain text file UpdateAction.php Class Class source
  Plain text file UpdateRelationshipAction.php Class Class source
  Plain text file ViewAction.php Class Class source
  Plain text file ViewForIdentityAction.php Class Class source
  Plain text file ViewRelationshipAction.php Class Class source

  Files folder image Files (94)  /  src  /  exceptions  
File Role Description
  Plain text file NonJsonApiResponseException.php Class Class source
  Plain text file ValidationException.php Class Class source

  Files folder image Files (94)  /  src  /  pagination  
File Role Description
  Plain text file CursorPagination.php Class Class source
  Plain text file JsonApiPaginator.php Class Class source

  Files folder image Files (94)  /  src  /  providers  
File Role Description
  Plain text file CursorActiveDataProvider.php Class Class source
  Plain text file JsonApiActiveDataProvider.php Class Class source
  Plain text file JsonApiArrayDataProvider.php Class Class source
  Plain text file JsonApiDataProviderInterface.php Class Class source
  Plain text file JsonApiSort.php Class Class source

  Files folder image Files (94)  /  tests  
File Role Description
Files folder imagecodeception (3 directories)
Files folder imagedocker (3 files)
Files folder imagetestapp (1 file, 6 directories)
Files folder imagetests_phpstorm (4 files)

  Files folder image Files (94)  /  tests  /  codeception  
File Role Description
Files folder imagesuites (2 directories)
Files folder image_data (1 file)
Files folder image_support (2 files, 1 directory)

  Files folder image Files (94)  /  tests  /  codeception  /  suites  
File Role Description
Files folder imageapi (6 files)
Files folder imageunit (5 files)

  Files folder image Files (94)  /  tests  /  codeception  /  suites  /  api  
File Role Description
  Plain text file ApiCategoryCest.php Class Class source
  Plain text file ApiDefaultCest.php Class Class source
  Plain text file ApiPostCest.php Class Class source
  Plain text file ApiRelationshipsCest.php Class Class source
  Plain text file ApiSortWithJoinsCest.php Class Class source
  Plain text file ApiUserCest.php Class Class source

  Files folder image Files (94)  /  tests  /  codeception  /  suites  /  unit  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Configuration script
  Plain text file JsonApiActionTest.php Class Class source
  Plain text file JsonApiDataProviderTest.php Class Class source
  Plain text file JsonApiPaginatorTest.php Class Class source
  Plain text file RelationsPatcherTest.php Class Class source

  Files folder image Files (94)  /  tests  /  codeception  /  _data  
File Role Description
  Accessible without login Plain text file dump.sql Data Auxiliary data

  Files folder image Files (94)  /  tests  /  codeception  /  _support  
File Role Description
Files folder imageHelper (1 file)
  Plain text file ApiTester.php Class Class source
  Plain text file UnitTester.php Class Class source

  Files folder image Files (94)  /  tests  /  codeception  /  _support  /  Helper  
File Role Description
  Plain text file Api.php Class Class source

  Files folder image Files (94)  /  tests  /  docker  
File Role Description
  Accessible without login Plain text file apache.conf Data Auxiliary data
  Accessible without login Plain text file Dockerfile Data Auxiliary data
  Accessible without login Plain text file xdebug.ini Data Auxiliary data

  Files folder image Files (94)  /  tests  /  testapp  
File Role Description
Files folder imageconfig (3 files)
Files folder imagecontrollers (5 files)
Files folder imagemigrations (4 files)
Files folder imagemodels (4 files)
Files folder imagetransformers (6 files)
Files folder imageweb (2 files)
  Accessible without login Plain text file yii Example Example script

  Files folder image Files (94)  /  tests  /  testapp  /  config  
File Role Description
  Plain text file api.php Class Class source
  Plain text file console.php Class Class source
  Accessible without login Plain text file test.php Aux. Configuration script

  Files folder image Files (94)  /  tests  /  testapp  /  controllers  
File Role Description
  Plain text file CategoryController.php Class Class source
  Plain text file CommentController.php Class Class source
  Plain text file DefaultController.php Class Class source
  Plain text file MeController.php Class Class source
  Plain text file PostController.php Class Class source

  Files folder image Files (94)  /  tests  /  testapp  /  migrations  
File Role Description
  Plain text file m200909_043143_create_users_table.php Class Class source
  Plain text file m200909_043417_cre...ategories_table.php Class Class source
  Plain text file m200909_043742_create_posts_table.php Class Class source
  Plain text file m200909_044342_create_comments_table.php Class Class source

  Files folder image Files (94)  /  tests  /  testapp  /  models  
File Role Description
  Plain text file Category.php Class Class source
  Plain text file Comment.php Class Class source
  Plain text file Post.php Class Class source
  Plain text file User.php Class Class source

  Files folder image Files (94)  /  tests  /  testapp  /  transformers  
File Role Description
  Plain text file CategoryTransformer.php Class Class source
  Plain text file CommentTransformer.php Class Class source
  Plain text file PostShortTransformer.php Class Class source
  Plain text file PostTransformer.php Class Class source
  Plain text file UserExtendTransformer.php Class Class source
  Plain text file UserTransformer.php Class Class source

  Files folder image Files (94)  /  tests  /  testapp  /  web  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (94)  /  tests  /  tests_phpstorm  
File Role Description
  Accessible without login Plain text file categories.http Data Auxiliary data
  Accessible without login Plain text file comments.http Data Auxiliary data
  Accessible without login Plain text file default.http Data Auxiliary data
  Accessible without login Plain text file posts.http Data Auxiliary data

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  
 100%
Total:0
This week:0