PHPackages                             alcalyn/serializable-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. alcalyn/serializable-api-response

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

alcalyn/serializable-api-response
=================================

Allows to return raw object as controller response so that it will be serialized later by serializer and converted to Symfony Response.

1.1.0(8y ago)04473MITPHPPHP &gt;=5.4

Since May 30Pushed 8y agoCompare

[ Source](https://github.com/alcalyn/serializable-api-response)[ Packagist](https://packagist.org/packages/alcalyn/serializable-api-response)[ Docs](https://github.com/alcalyn/serializable-api-response)[ RSS](/packages/alcalyn-serializable-api-response/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (3)

Serializable Api Response
=========================

[](#serializable-api-response)

If you use Symfony Http foundation and JMS Serializer, this library allows to return raw objects and status code as a controller response so that it will be serialized later by serializer and converted to a Symfony Response.

**The problem**: Symfony converts response content to string if we use Symfony Response, or if we return a raw object and use a filter listener, then we can't pass status code.

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

[](#installation)

Install via composer

```
{
    "require": {
        "alcalyn/serializable-api-response": "~1.0"
    }
}
```

Usage
-----

[](#usage)

Return a non-yet-serialized response in your controller:

```
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Alcalyn\SerializableApiResponse\ApiResponse;
use Acme\UserApi\Exception\UserAlreadyExistsException;

class UserController
{
    /**
     * @param Request $request
     *
     * @return ApiResponse
     *
     * @throws ConflictHttpException if username already exists.
     */
    public function registerUserAction(Request $request)
    {
        $username = $request->request->get('username');
        $password = $request->request->get('password');

        try {
            $user = $this->userManager->createUser($username, $password);
        } catch (UserAlreadyExistsException $e) {
            throw new ConflictHttpException('An user with username "'.$username.'" already exists.', $e);
        }

        return new ApiResponse($user, Response::HTTP_CREATED);
    }
}
```

Register ApiResponse Filter Listener:

In Silex:

```
use Symfony\Component\HttpKernel\KernelEvents;
use Alcalyn\SerializableApiResponse\ApiResponseFilter;

// Register reponse filter as a service
$this['acme.listener.api_response_filter'] = function () {
    $serializer = $this['serializer']; // Assuming your serializer service has this name

    return new ApiResponseFilter($serializer);
};

// Listen Kernel response to convert ApiResponse with raw object to Symfony Response with serialized data
$this->on(KernelEvents::VIEW, function ($event) {
    $this['acme.listener.api_response_filter']->onKernelView($event);
});
```

License
-------

[](#license)

This project is under [MIT Lisense](LICENSE)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~694 days

Total

2

Last Release

2987d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f0c4d65197a7aed6ecc8fdedd5a097c7238c9be19aca08c92c05d38fd8c29e?d=identicon)[alcalyn](/maintainers/alcalyn)

---

Top Contributors

[![alcalyn](https://avatars.githubusercontent.com/u/1588144?v=4)](https://github.com/alcalyn "alcalyn (2 commits)")

---

Tags

symfonyserializer

### Embed Badge

![Health badge](/badges/alcalyn-serializable-api-response/health.svg)

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

###  Alternatives

[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k50.1M314](/packages/api-platform-core)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[sulu/sulu

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

1.3k1.4M196](/packages/sulu-sulu)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k246.0M11.1k](/packages/symfony-framework-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k181.3M2.2k](/packages/symfony-security-bundle)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k172.8M350](/packages/symfony-security-http)

PHPackages © 2026

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