gowork/symfony-json-request

Symfony Json Request

Installs: 15 175

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

v0.2.1 2022-06-02 20:32 UTC

This package is auto-updated.

Last update: 2024-04-07 17:32:06 UTC


README

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