PHPackages                             giadc/json-api-response - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. giadc/json-api-response

AbandonedArchivedLibrary

giadc/json-api-response
=======================

A package for handling JSON API responses

4.0.0(1y ago)16.0k31MITPHPPHP &gt;=8.1

Since Feb 29Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/giadc/json-api-response)[ Packagist](https://packagist.org/packages/giadc/json-api-response)[ RSS](/packages/giadc-json-api-response/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (10)Versions (22)Used By (1)

GIADC JSON Response Package
===========================

[](#giadc-json-response-package)

`currently: v0.1`

This package makes it easy to return HTTP API responses that fit the [JSON API](http://jsonapi.org/) standard.

Installation
------------

[](#installation)

Via Composer

```
$ composer require giadc/giadc-json-response
```

#### Laravel

[](#laravel)

Add the following to the `providers` array of your `config/app.php`

```
Giadc\JsonApiResponse\ServiceProviders\LaravelDoctrineServiceProvider::class,
```

Usage
-----

[](#usage)

Basic Example:

```
use Giadc\JsonResponse\Responses\Response;

class YourClass {
    _construct(Response $response) {
        $this->response = $response;
    }

    public function jsonApiFunctions() {

        return $this->response->success();
    }
}
```

Available functions:

```
$response->getStatusCode(): int;
$response->setStatusCode(int $statusCode);
$response->withArray(array $array, array $headers = []): JsonResponse;
$response->withError(string $message): JsonResponse;
$response->createSuccessful( $entity = null, TransformerAbstract $transformer = null, string $resourceKey = '', array $headers = []): SymfonyResponse;
$response->withItem( $item, TransformerAbstract $transformer, string $resourceKey, array $headers = []): JsonResponse;
$response->withResourceItem( JsonApiResource $item, ResourceTransformer $transformer, array $headers = []): JsonResponse;
$response->withCollection( $collection, TransformerAbstract $transformer, string $resourceKey = ''): SymfonyResponse;
$response->noContent(array $headers = []): JsonResponse;
$response->withPaginatedCollection(PaginatedCollection $paginator, TransformerAbstract $transformer, string $resourceKey = ''): JsonResponse;
$response->withHttpException( HttpExceptionInterface $httpException): JsonResponse;
$response->errorForbidden(string $message = 'Forbidden'): JsonResponse;
$response->errorInternalError(string $message = 'Internal Error'): JsonResponse;
$response->errorNotFound(string $message = 'Not Found'): JsonResponse;
$response->errorUnauthorized(string $message = 'Unauthorized'): JsonResponse;
$response->errorValidation(string $message = 'Validation Error'): JsonResponse;
$response->errorsValidation(array $messages): JsonResponse;
$response->errorNotSearchable(string $message = 'Not Searchable'): JsonResponse;
```

Fractal Transformers
--------------------

[](#fractal-transformers)

The GIADC JSON Response packages uses `league/fractal` for the `withItem()`, `withCollection()`, &amp; `withPaginatedCollection()` responses. See [Fractal's documentation](http://fractal.thephpleague.com/transformers) for more information regarding Transformers.

ResourceTransformer
-------------------

[](#resourcetransformer)

ResourceTransformer adds the required `transform` that pulls JsonApiResource's data from the required `jsonSerialize` method. It also allows for automatic management of `excludes` and `fields` request parameters options.

JsonApiResource
---------------

[](#jsonapiresource)

Forces entities to have the following methods:

- getResourceKey: We can now reference this instead of hard coding this value very time.
- id: JsonAPI allows requires an id.
- jsonSerialize: Used in the new ResourceTransformer.

Use the JsonApiResource Item response to automatically pass `$resourceKey` to the transformer. `$response->withResourceItem($item, $transformer, $headers)`

Excludes
--------

[](#excludes)

not supported by JsonAPI

Attributes may be excluded from JsonApiResource's response. A decent use case for this would be removing the config/ui/tracking from Campaigns when it's not needed. This would allow us to remove some redundant routes, providing the FE with more flexibility.

Example:

`/api/export/campaigns?excludes[campaigns]=config,ui`

Fields ()
----------------------------------------------------------------

[](#fields-httpsjsonapiorgformatfetching-sparse-fieldsets)

> An empty value indicates that no fields should be returned. ... If a client requests a restricted set of fields for a given resource type, an endpoint MUST NOT include additional fields in resource objects of that type in its response.

Example: `/api/permissionGroups?fields[permissionGroups]=name&include=permissions&fields[permissions]=`

```
{
  "data": [
    {
      "type": "permissionGroups",
      "id": "adops",
      "attributes": { "name": "adops" },
      "relationships": {
        "permissions": {
          "data": [{ "type": "permissions", "id": "campaigns.tracking" }]
        }
      }
    },
  ],
  "included": [
    { "type": "permissions", "id": "campaigns.tracking", "attributes": {} }
  ]
}

```

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance58

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Recently: every ~422 days

Total

20

Last Release

659d ago

Major Versions

0.1.6 → 1.0.02016-08-12

1.4.0 → 2.0.02020-11-17

2.x-dev → 3.0.02022-09-12

3.0.0 → 4.0.02024-07-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/98443c90baa66d3472ebe1dc3fb9ff843a6dd278b7b0a52e8c7732e722c6494e?d=identicon)[giadc-dev](/maintainers/giadc-dev)

---

Top Contributors

[![rmarganti](https://avatars.githubusercontent.com/u/1193396?v=4)](https://github.com/rmarganti "rmarganti (20 commits)")[![dhill2-gannett](https://avatars.githubusercontent.com/u/225896226?v=4)](https://github.com/dhill2-gannett "dhill2-gannett (7 commits)")[![davidxhill](https://avatars.githubusercontent.com/u/3369259?v=4)](https://github.com/davidxhill "davidxhill (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/giadc-json-api-response/health.svg)

```
[![Health](https://phpackages.com/badges/giadc-json-api-response/health.svg)](https://phpackages.com/packages/giadc-json-api-response)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[concrete5/core

Concrete core subtree split

19159.3k48](/packages/concrete5-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
