PHPackages                             paveldanilin/request-body-bundle - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. paveldanilin/request-body-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

paveldanilin/request-body-bundle
================================

A Symfony RequestBody Bundle

v2.2.4(3y ago)81.8k1MITPHPPHP &gt;=7.4

Since Jan 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/paveldanilin/request-body-bundle)[ Packagist](https://packagist.org/packages/paveldanilin/request-body-bundle)[ RSS](/packages/paveldanilin-request-body-bundle/feed)WikiDiscussions 2.2.x Synced 2d ago

READMEChangelogDependencies (15)Versions (26)Used By (0)

### @RequestBody annotation

[](#requestbody-annotation)

RequestBody is a way to populate objects and inject them as controller method arguments.

The Request body converter makes it possible to deserialize the request body into an object.

#### Install

[](#install)

`composer require paveldanilin/request-body-bundle`

#### Usage

[](#usage)

By default, RequestBody is trying to populate the single defined parameter.

```
/**
 * @Route("/users", methods={"POST"})
 *
 * @RequestBody
 *
 * @param User $user
 * @return Response
 */
public function createUser(User $user): Response
{
    return new Response();
}
```

If a method has several parameters we should explicitly define the parameter for populating.

```
/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user")
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}
```

#### Deserialization

[](#deserialization)

We can specify a deserialization context.

More about the object deserialization you can find [here](https://symfony.com/doc/4.4/components/serializer.html#deserializing-an-object)

```
/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", deserializationContext={"someAttribute"="value"})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}
```

Also, it is possible to replace the deserialization error message with a custom message.

```
/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", deserializationError="Bad DTO")
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}
```

#### Validation

[](#validation)

By default, validation will be performed for each assertion which is defined per DTO.

For the following DTO will be performed two assertions after a deserialization process.

```
class User
{
    /**
     * @Assert\NotBlank(allowNull=false)
     * @Assert\Type(type="string")
     *
     * @var string
     */
    public $name;
}
```

We can avoid a validation process by defining the `validationGroups` attribute as an empty array.

```
/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", validationGroups={})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}
```

Or we can explicitly define validation groups by means of `validationGroups` attribute.

```
/**
 * @Route("/users", methods={"PATCH"})
 *
 * @RequestBody("user", validationGroups={"edit"})
 *
 * @param int $userId
 * @param User $user
 * @return Response
 */
public function editUser(int $userId, User $user): Response
{
    return new Response();
}
```

You can read [more](https://symfony.com/doc/4.4/validation.html) about a validation process.

#### Debug

[](#debug)

The bundle comes with a handy console command which shows all controllers that use the @RequestBody annotation

```
$ php bin/console debug:request-body

+--------------------+----------------------+---------------------------------------------------------------------------------------+----------------------------------------------------+--------------------+
| Class              | Method               | Bind Param                                                                            | Param Type                                         | Validation Context |
+--------------------+----------------------+---------------------------------------------------------------------------------------+----------------------------------------------------+--------------------+
| TestUserController | createUser           | user                                                                                  | paveldanilin\RequestBodyBundle\Tests\Fixtures\User | all                |
| TestUserController | editUser             | Method does not have such parameter 'user'                                            |                                                    | all                |
| TestUserController | noTypeHint           | The 'user' parameter does not have a type hint                                        |                                                    | all                |
| TestUserController | autoMap              | user                                                                                  | paveldanilin\RequestBodyBundle\Tests\Fixtures\User | all                |
| TestUserController | autoMapNoParams      | Could not autodetect parameter for body mapping. The method does not have parameters. |                                                    | all                |
| TestUserController | autoMapTooManyParams | Could not autodetect parameter for body mapping. The method has too many parameters.  |                                                    | all                |
+--------------------+----------------------+---------------------------------------------------------------------------------------+----------------------------------------------------+--------------------+

```

#### Test

[](#test)

- `composer test`

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.8% 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 ~28 days

Recently: every ~78 days

Total

24

Last Release

1309d ago

Major Versions

v1.0.10 → v2.0.02021-06-16

v2.2.4 → 3.x-dev2022-10-12

PHP version history (2 changes)v1.0.0PHP &gt;=7.2

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b12bdb9c0f7d0eaeac115fb72645c4d93e0f38f4aa2a84b8d8bcef1a09773ecd?d=identicon)[paveldanilin](/maintainers/paveldanilin)

---

Top Contributors

[![paveldanilin](https://avatars.githubusercontent.com/u/1683893?v=4)](https://github.com/paveldanilin "paveldanilin (45 commits)")[![Seldaek](https://avatars.githubusercontent.com/u/183678?v=4)](https://github.com/Seldaek "Seldaek (1 commits)")

---

Tags

annotationbundlephprequest-bodysymfonysymfony-bundlesymfonybundleannotationrequest-body

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/paveldanilin-request-body-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/paveldanilin-request-body-bundle/health.svg)](https://phpackages.com/packages/paveldanilin-request-body-bundle)
```

###  Alternatives

[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[ec-cube/ec-cube

EC-CUBE EC open platform.

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

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

50570.7k1](/packages/web-auth-webauthn-framework)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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