gowork/symfony-json-request

Symfony Json Request

安装次数: 17,299

依赖者: 0

建议者: 0

安全性: 0

星标: 2

关注者: 3

分支: 0

公开问题: 0

类型:symfony-bundle

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

This package is auto-updated.

Last update: 2024-09-07 18:22:48 UTC


README

将JSON请求体转换为请求数组。

安装

composer require gowork/symfony-json-request

设置包

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

用法

当发送包含JSON体和 application/json 内容类型的请求时,此包将JSON键转换为symfony请求键

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