PHPackages                             akrabat/rka-content-type-renderer - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. akrabat/rka-content-type-renderer

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

akrabat/rka-content-type-renderer
=================================

Render an array to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

2.0(4y ago)40443.2k↓11.7%10[2 issues](https://github.com/akrabat/rka-content-type-renderer/issues)1BSD-3-ClausePHPPHP ^7.3 || ^8.0CI failing

Since Oct 12Pushed 2y ago4 watchersCompare

[ Source](https://github.com/akrabat/rka-content-type-renderer)[ Packagist](https://packagist.org/packages/akrabat/rka-content-type-renderer)[ Docs](http://github.com/akrabat/rka-content-type-renderer)[ RSS](/packages/akrabat-rka-content-type-renderer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (7)Versions (19)Used By (1)

Render output based on content-type
===================================

[](#render-output-based-on-content-type)

Render an array (or HAL object) to a JSON/XML/HTML PSR-7 Response based on a PSR-7 Request's Accept header.

[![Build status](https://camo.githubusercontent.com/b48f7fde6729885d58971b03d324b7647a54d4b0cfb73c58a8b6d96dea5864e8/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f616b72616261742f726b612d636f6e74656e742d747970652d72656e64657265722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/akrabat/rka-content-type-renderer)

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

[](#installation)

`composer require akrabat/rka-content-type-renderer`

Usage
-----

[](#usage)

```
// given:
// $request instanceof Psr\Http\Message\RequestInterface
// $response instanceof Psr\Http\Message\ResponseInterface

$data = [
    'items' => [
        [
            'name' => 'Alex',
            'is_admin' => true,
        ],
        [
            'name' => 'Robin',
            'is_admin' => false,
        ],
    ],
];
$renderer = new RKA\ContentTypeRenderer\Renderer();
$response  = $renderer->render($request, $response, $data);
return $response->withStatus(200);
```

The constructor takes a parameter, `$pretty` that defaults to `true`. Set to `false` to disable pretty printing.

HalRenderer
-----------

[](#halrenderer)

This component also supports [nocarrier/hal](https://github.com/blongden/hal) objects with the `HalRenderer`:

```
$hal = new Nocarrier\Hal(
    '/foo',
    [
        'items' => [
            [
                'name' => 'Alex',
                'is_admin' => true,
            ],
            [
                'name' => 'Robin',
                'is_admin' => false,
            ],
        ],
    ]
);
$renderer = new RKA\ContentTypeRenderer\HalRenderer();
$response  = $renderer->render($request, $response, $hal);
return $response->withStatus(200);
```

ApiRenderer
-----------

[](#apirenderer)

This component also supports [crell/ApiProblem](https://github.com/Crell/ApiProblem) objects with the `ApiProblemRenderer`:

```
$problem = new Crell\ApiProblem("Something unexpected happened");
$renderer = new RKA\ContentTypeRenderer\ApiProblemRenderer();
$response  = $renderer->render($request, $response, $problem);
return $response->withStatus(500);
```

Arrays of objects
-----------------

[](#arrays-of-objects)

If you have an array of objects, then the renderer will still work as long as the objects implement PHP's JsonSerializable interface.

Testing
-------

[](#testing)

- Code style: `$ phpcs`
- Unit tests: `$ phpunit`
- Code coverage: `$ phpunit --coverage-html ./build`

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 86.5% 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 ~145 days

Recently: every ~428 days

Total

16

Last Release

1686d ago

Major Versions

0.8.0 → 1.02019-09-29

1.0 → 2.02021-10-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33135?v=4)[Rob Allen](/maintainers/akrabat)[@akrabat](https://github.com/akrabat)

---

Top Contributors

[![akrabat](https://avatars.githubusercontent.com/u/33135?v=4)](https://github.com/akrabat "akrabat (83 commits)")[![tscheckenbach](https://avatars.githubusercontent.com/u/112858?v=4)](https://github.com/tscheckenbach "tscheckenbach (11 commits)")[![cruzcraul](https://avatars.githubusercontent.com/u/9257605?v=4)](https://github.com/cruzcraul "cruzcraul (1 commits)")[![stefanotorresi](https://avatars.githubusercontent.com/u/2952427?v=4)](https://github.com/stefanotorresi "stefanotorresi (1 commits)")

---

Tags

jsonxmlpsr7

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/akrabat-rka-content-type-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/akrabat-rka-content-type-renderer/health.svg)](https://phpackages.com/packages/akrabat-rka-content-type-renderer)
```

###  Alternatives

[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[laminas/laminas-xml2json

Provides functionality for converting XML to JSON, optionally including XML attributes

14408.5k13](/packages/laminas-laminas-xml2json)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)[danharper/laravel-jsonx

Add XML support to a JSON-speaking Laravel API with a single middleware via JSONx

1857.2k](/packages/danharper-laravel-jsonx)

PHPackages © 2026

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