Skip to content

gowork/symfony-json-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Request Bundle

Converts json request body to request array.

Install

composer require gowork/symfony-json-request

Setup bundle

<?php
public function registerBundles(): array
{
    $bundles = [
        // ...
        new GW\SymfonyJsonRequest\SymfonyJsonRequestBundle(),
    ];
    ...
}

Usage

When sending request with json body and application/json content type, this bundle converts json keys to symfony request keys:

<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

public function controllerAction(Request $request): Response
{
    $content = (string)$request->request->get('content');
}
curl 'controller/path' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  --data-binary '{"content"s:"test","nick":"test"}'