Download the PHP package serhiikamolov/laravel-jsonapi without Composer

On this page you can find all versions of the php package serhiikamolov/laravel-jsonapi. 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 laravel-jsonapi

Laravel JsonAPI

A set of interfaces and classes to facilitate the construction of an efficient JSON:API application with the Laravel framework.

Latest Stable Version License

Table of contents

Installation

This package is very easy to set up via Composer, just run from your project's root folder:

Custom error handler

In order to make errors output compatible with json API format go to bootstrap/app.php and register the custom error handler.

Or just extend default App\Exceptions\Handler from JsonAPI\Exceptions\Handler class.

Now, in case of an exception you will get such a response:

Request validation class

\JsonAPI\Contracts\Request is a simple extension of the FormRequest class that returns the validation errors in compatible with the json API form

Example of a controller with request validation:

Response with validation errors:

Response class

JsonAPI\Response\Response is an exension of the JsonResponse class with some additional methods.

Add additional values to the links object of the response

Return error with the specific code in the response

Return response with JWT token

Return a custom data object in the response

Attach a field to the response's data object

Add a debug information to the response object

Add a meta data to the response object

Serialize an eloquent collection or a data model

Paginate a data array in the response

Add a specific status code to the response

Response class is an implementation of the Builder pattern thus you can use diffrent methods in a row:

Response result:

Serializer class

Serializers allow complex data such as Eloquent Collections and Model instances to be converted to a simple array that can be easily rendered into JSON. Serializer class gives you a powerful, generic way to control the output of your responses.

Declaring Serializers

Let's create a simple serializer class extended from the JsonAPI\Response\Serializer class. There is a public method fields() which returns an array, and define a set of fields which will be retrieved from the given Collection or Model and put to the response.

Here you can notice that uuid is not taken from the database but generated from the model data. In such a way you can define any new field you need in the response or even override an existing field value.

Using Model Serializers

There is serialize method in the JsonAPI\Response\Response class which accept a Serializer instance as a second parameter.

Response result

Using Field Modifiers

Field modifiers can be applied to every field defined in serializer. Although, there are a few predefined modifiers: timestamp, number, trim you can define your own modifier by creating a protected method with the modifier prefix in its name. Also you can use another serializing class as a modifier, it can be useful when you have some related data to the original model.

Expand Response with the Queries Log

Enable JsonAPI\Http\Middleware\JsonApiDebug middleware and expand the debug section of a response with the information from the queries log.

Response with the queries log.

Testing API Responses

Add JsonAPI\Traits\Tests\JsonApiAsserts trait to your default TestCase class and expand your tests with some useful asserts methods for testing API responses.

Example of using additional asserts:


All versions of laravel-jsonapi with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
illuminate/http Version ^11.1
illuminate/database Version ^11.1
illuminate/pagination Version ^11.0
illuminate/support Version ^11.0
illuminate/routing Version ^11.0
illuminate/auth Version ^11.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 serhiikamolov/laravel-jsonapi contains the following files

Loading the files please wait ....