Skip to content

Bundle eases work with JSON requests and treats them as standard requests without using «crutches».

License

Notifications You must be signed in to change notification settings

nowiko/JsonRequestBundle

Repository files navigation

Build Status Scrutinizer Code Quality

JsonRequest Bundle

This bundle is a copy (with some minor changes) of JsonRequest Bundle which, for some reasons, was deleted by authors.

It eases work with JSON requests and treats them as standard requests without using «crutches».

Installation

  1. Require the bundle with composer:
composer require nw/json-request-bundle
  1. Register the bundle in the application: In app/AppKernel.php prior to Symfony version 4.0:
public function registerBundles()
{
    $bundles = [
        // ... ,
        new NW\JsonRequestBundle\NWJsonRequestBundle()
    ];

    // ...
    return $bundles;
}

In config/bundles.php when Symfony version is 4.0 and higher

return [
    //... other bundles
    NW\JsonRequestBundle\NWJsonRequestBundle::class => ['all' => true]
];

Usage

Previously to handle JSON-request, you were forced to do something similar to:

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

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

With this bundle you can work with JSON-request as with standard request:

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

About

Bundle eases work with JSON requests and treats them as standard requests without using «crutches».

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages