Download the PHP package intermax/laravel-json-api without Composer

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

Laravel JSON:API

Laravel API is a package to quickly build an API according to the JSON:API specification. It also generates OpenAPI documentation on the fly based on your API endpoints.

Installation

Configuration

To render exceptions in JSON:API format, you can add the middleware Intermax\LaravelJsonApi\Middleware\RenderJsonApiExceptions to applicable routes. A sensible example would be in the HTTP Kernel in the API middleware group:

Basic Usage

To create an endpoint you just create a Laravel route like you're used to doing. After that you need to create a resource. Let's assume we make an endpoint that returns a UserResource:

After that you should create your controller method. Generally you would want an API Resource Controller. If you return the resource you just made your first endpoint with the Laravel API package:

TIP: Make sure to type hint your resource on the controller method so Open API docs can be generated correctly. Read more about this at Open API generation

Query Parameters

You might want ways to apply filters, sorts and includes to your requests. With JSON:API this is done by applying a filter, sort and include variables to the query string:

CollectionRequest

With this package you can configure some predefined filters or add your own. You can also add includes and sorts. To do this you can add a CollectionRequest to your controller method. Essentially this is an extended FormRequest. Your custom CollectionRequest needs to extend the Intermax\LaravelJsonApi\Requests\CollectionRequest. It might look like this:

This specific CollectionRequest adds two filters, filter[createdAt] and filter[isAdmin]. To see how these specific filters work, see filter types.

Controller

To make the filters, includes and sorts actually do their magic, we need a little more. In the controller the QueryResolver needs to be used to apply the filters to the Eloquent query. Under the hood this uses the laravel-query-builder package from spatie.

Filter Types

This package provides two types of filters out of the box. One is the ScopeFilter. Like its name implies this will call the scope with the value that's being sent.

The second one is called the OperatorFilter. It allows you to query with a set of operators:

Allowed operators can be specified (default all are allowed):

Mutation Requests

For POST, PUT or PATCH requests this package provides an extendable base request for convenience. Instead of a regular FormRequest you know from Laravel it should extend the MutationRequest. This class helps you to adhere to the JSON:API specification for your requests:

⚠️ WARNING: Be aware that if you were previously not checking for the content type you could easily create a breaking change in your application.

Usage

An example implementation may look like this:

And in the controller you can use the methods to retrieve validated fields:

OpenAPI Generation

This package leverages the Laravel Open API package to provide a /docs endpoint (and /docs/json and /docs/yaml endpoints).

The open API package will scan for api routes, read FormRequests, determine ApiResources and try to guess the output of the resource. We aim to generate as much documentation as possible with a minimal amount of configuration.

There are a couple of things that need to be in place for this to work best:

Improving resource attribute data types

If you look at the docs and see all your resource attributes are listed as string in the array, there is one more thing you can do to improve it. Wrap every field in a Intermax\LaravelOpenApi\Generator\Values\Value type object:


All versions of laravel-json-api with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-json Version *
intermax/laravel-open-api Version ^2.0
laravel/framework Version ^10.0 || ^11.0
spatie/laravel-json-api-paginate Version ^1.12
spatie/laravel-query-builder Version ^5.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 intermax/laravel-json-api contains the following files

Loading the files please wait ....