Giter Club home page Giter Club logo

request-body-parser's Introduction

Yii

Yii Request Body Parser


Latest Stable Version Total Downloads Build status Code coverage Mutation testing badge static analysis type-coverage

The package is PSR-15 middleware that allows parsing PSR-7 server request body selecting the parser according to the server request mime type.

Requirements

  • PHP 7.4 or higher.

Installation

The package could be installed with Composer:

composer require yiisoft/request-body-parser

General usage

  1. Add RequestBodyParser to your middleware stack.
  2. Obtain parsed body via $request->getParsedBody();.

By default, it parses application/json requests where JSON is in the body.

You can add your own parser by implementing ParserInterface, adding it into the container and registering it within the middleware:

$requestBodyParser = $requestBodyParser->withParser('application/myformat', MyFormatParser::class);

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Yii Request Body Parser is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

request-body-parser's People

Contributors

bautrukevich avatar devanych avatar fantom409 avatar luizcmarin avatar roxblnfk avatar rustamwin avatar samdark avatar sankaest avatar siamskoi avatar terabytesoftw avatar thenotsoft avatar viktorprogger avatar vjik avatar xepozz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

request-body-parser's Issues

RequestBodyParser does not support scalar JSON values (bool, int, float, string)

What steps will reproduce the problem?

  1. Use the Yiisoft\Request\Body\Parser\JsonParser to parse a JSON body containing scalar values such as true, 42, 3.14, or "hello".
  2. Observe that the Yiisoft\Request\Body\Parser\JsonParser does not handle these scalar values correctly.

What is the expected result?

The RequestBodyParser should correctly parse JSON bodies containing scalar values (boolean, integer, float, string) and return these values without errors.

json_decode('true');   // Expected result: true (boolean)
json_decode('42');     // Expected result: 42 (integer)
json_decode('3.14');   // Expected result: 3.14 (float)
var_dump(json_decode('-1e3')); // Expected -1000 (float)
json_decode('"hello"');// Expected result: "hello" (string)

What do you get instead?

The RequestBodyParser fails to handle JSON bodies with scalar values and does not return the expected result. Instead, it only supports objects and arrays.

Q A
Version 1.0.?
PHP version any
Operating system any

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.