/json-request-bundle

Symfony Json Request Bundle

Primary LanguagePHPMIT LicenseMIT

SymfonyBundlesJsonRequestBundle

SensioLabsInsight

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version License

What is JsonRequest Bundle?

This bundle will help you to work with json requests as standard requests without using «crutches». If previously for fetching of data from the request you did like this: $data = json_decode($request->getContent()), it is now in this already there is no need to.

For example when sending json-request from AngularJS or etc. Early:

public function indexAction(Request $request)
{
    $data = json_decode($request->getContent());

    // uses request data
    $name = isset($data['name']) ? $data['name'] : null;
}

Now you can work with json-request as with standard request:

public function indexAction(Request $request)
{
    $name = $request->get('name');
}

Installation

  • Require the bundle with composer:
composer require symfony-bundles/json-request-bundle
  • Enable the bundle in the kernel:
public function registerBundles()
{
    $bundles = [
        // ...
        new SymfonyBundles\JsonRequestBundle\SymfonyBundlesJsonRequestBundle(),
        // ...
    ];
    ...
}