Download the PHP package tuyakhov/yii2-json-api without Composer

On this page you can find all versions of the php package tuyakhov/yii2-json-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 yii2-json-api

Implementation of JSON API specification for the Yii framework

Latest Stable Version Scrutinizer Code Quality Build Status Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json file.

Data Serializing and Content Negotiation:

Controller:

By default, the value of type is automatically pluralized. You can change this behavior by setting tuyakhov\jsonapi\Serializer::$pluralize property:

Defining models: 1) Let's define User model and declare an articles relation

2) Now we need to define Article model

3) As the result User model will be serialized into the proper json api resource object:

Controlling JSON API output

The JSON response is generated by the tuyakhov\jsonapi\JsonApiResponseFormatter class which will use the yii\helpers\Json helper internally. This formatter can be configured with different options like for example the $prettyPrint option, which is useful on development for better readable responses, or $encodeOptions to control the output of the JSON encoding.

The formatter can be configured in the yii\web\Response::formatters property of the response application component in the application configuration like the following:

Links

Your resource classes may support HATEOAS by implementing the LinksInterface. The interface contains getLinks() method which should return a list of links. Typically, you should return at least the self link representing the URL to the resource object itself. In order to appear the links in relationships getLinks() method should return self link. Based on this link each relationship will generate self and related links. By default it happens by appending a relationship name at the end of the self link of the primary model, you can simply change that behavior by overwriting getRelationshipLinks() method. For example,

As the result:

Pagination

The page query parameter family is reserved for pagination. This library implements a page-based strategy and allows the usage of query parameters such as page[number] and page[size]
Example: http://yourdomain.com/users?page[number]=3&page[size]=10

Enabling JSON API Input

To let the API accept input data in JSON API format, configure the [[yii\web\Request::$parsers|parsers]] property of the request application component to use the [[tuyakhov\jsonapi\JsonApiParser]] for JSON input

By default it parses a HTTP request body so that you can populate model attributes with user inputs. For example the request body:

Will be resolved into the following array:

So you can access request body by calling \Yii::$app->request->post() and simply populate the model with input data:

By default type users will be converted into User (singular, camelCase) which corresponds to the model's formName() method (which you may override). You can override the JsonApiParser::formNameCallback property which refers to a callback that converts 'type' member to form name. Also you could change the default behavior for conversion of member names to variable names ('first-name' converts into 'first_name') by setting JsonApiParser::memberNameCallback property.

Examples

Controller:

Model:

Configuration file config/main.php:


All versions of yii2-json-api with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ^2.0.13
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 tuyakhov/yii2-json-api contains the following files

Loading the files please wait ....