Download the PHP package bitnetic/jsonapi without Composer

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

JsonApi.org compability package for Laravel 5.5+

This package is intended to provide an easy way to achieve compatibility with the API standards defined at http://jsonapi.org. Currently, only the top-level structure (http://jsonapi.org/format/#document-top-level) is supported, but ongoing work strives for a more complete coverage of the standard.

How to install it

You can install the package via composer. For Laravel 5.5 up to 6.x run:

$ composer require bitnetic/jsonapi "0.1.*"

For Laravel 7 run:

$ composer require bitnetic/jsonapi "^2.0"

JsonApi comes with a config file named config/jsonapi.php. This file is deployed to the central laravel configuration directory using the vendor:publish command:

$ php artisan vendor:publish --provider "Bitnetic\JsonApi\JsonApiServiceProvider"

Next, extend your exception handler with JsonApi standard responses. Note that this example uses the Laravel 7 signature that uses Throwable instead of Exception that was used in Laravel 5 and 6.

/**
 * Render an exception into an HTTP response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Throwable  $exception
 * @return \Illuminate\Http\Response
 */
public function render($request, Throwable $exception)
{
    return JsonApiExceptionHandler::render($request, $exception)
        ?? parent::render($request, $exception);
}

How to use it

This JsonApi package is minimal-invasive to Laravel. Just use HTTP resources within your controllers and extend them from JsonApiResource.

This is an example controller method:

/**
 * @return UserResource
 */
public function getUser(Request $request)
{
    return new UserResource($request->user());
}

You can also use collections in a list()-method by calling UserResource::collect($myUsers);.

Put extra data into the response

You can always add your own data into the meta or errors field, or return a different HTTP status code. The package just makes sure that the status code is mapped additionally as a status field within the meta block.

return new UserResource($myUser, ['type' => 'admin'], $exception->errors(), 404);

How to write an appropriate resource

Take a look at the following example:

class UserResource extends JsonApiResource
{
    public function toArray($request)
    {
        return [
            'name' => $this->name,
            'email' => $this->email,
            'password' => $this->when(
                $request->user() ... e.g.,
                MySecureTokenFactory::wrap($this->password),
        ];
    }
}

In a resource like UserResource($user), you can access the underlying user object by using $this.

You can also take a look the included ExampleResource and adopt it to your needs.

The outcome

The formatted Json-Api-Response from the examples above should produce something like this:

{
  "data": {
    "name": "John Doe",
    "email": "[email protected]"
  },
  "meta": {
    "status": 200
    "success": true
  }
}

All versions of jsonapi with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ^7.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 bitnetic/jsonapi contains the following files

Loading the files please wait ....