Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Request Bundle

Converts json request body to request array.

Starting from Symfony 6.3 there is native $request->getPayload() method that can be used instead of this package

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"}'

About

Converts json request body to request array

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages