Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nowiko/jsonrequestbundle
Bundle eases work with JSON requests and treats them as standard requests without using «crutches».
https://github.com/nowiko/jsonrequestbundle
json-requests jsonrequest-bundle symfony
Last synced: about 1 month ago
JSON representation
Bundle eases work with JSON requests and treats them as standard requests without using «crutches».
- Host: GitHub
- URL: https://github.com/nowiko/jsonrequestbundle
- Owner: nowiko
- License: mit
- Created: 2020-12-18T17:36:30.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-18T20:10:55.000Z (almost 4 years ago)
- Last Synced: 2024-10-01T15:27:03.760Z (about 2 months ago)
- Topics: json-requests, jsonrequest-bundle, symfony
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/nowiko/JsonRequestBundle.svg?branch=master)](https://travis-ci.org/nowiko/JsonRequestBundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nowiko/JsonRequestBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nowiko/JsonRequestBundle/?branch=master)
JsonRequest Bundle
=================================This bundle is a copy (with some minor changes) of [JsonRequest Bundle](https://github.com/symfony-bundles/json-request-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:
``` bash
composer require nw/json-request-bundle
```2) Register the bundle in the application:
In `app/AppKernel.php` prior to Symfony version `4.0`:
```php
public function registerBundles()
{
$bundles = [
// ... ,
new NW\JsonRequestBundle\NWJsonRequestBundle()
];// ...
return $bundles;
}
```In `config/bundles.php` when Symfony version is `4.0` and higher
```php
return [
//... other bundles
NW\JsonRequestBundle\NWJsonRequestBundle::class => ['all' => true]
];
```Usage
------------Previously to handle JSON-request, you were forced to do something similar to:
``` php
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:
``` php
public function indexAction(Request $request)
{
$name = $request->get('name');
}
```