HTTP Request input/body parser for php rest API.
This should be used as a body parser for an http request in a rest API;
Assuming that an http request can be sent with some information in different formats like: XML, JSON, YAML, and others; Request Input accepts all of the above, and can be complemented by creating a custom parser.
- From the prompt command line [cmd]
composer require php_modules/request-input
- composer.json
{
"require": {
"php_modules/request-input": "^1.0.1"
}
}
use Sammy\Packs\RequestInput;
$request = new RequestInput;
$body = $request->getRequestInput();
$request = requires ('request-input');
$body = $request->getRequestInput();
The '$body' variable should be evaluated acording to the request body.
Below is a list of data type matches supported by requestInput.
{
"user": {
"name": "Foo",
"email": "foo@bar",
"site": "foobar.baz"
}
}
user:
name: Foo
email: foo@bar
size: foobar.baz
<user>
<name>Foo</name>
<email>foo@bar</email>
<site>foobar.baz</site>
</user>
Any of the request body below should be send with a header acording to the used type; so RequestInput may parse the sent request body to be used in php.
Frameworks like @Samils should parse it automatically and provide the request body as a property of a '$request' object.
Using it inside a @Samils Controller should be done as bellow:
namespace Application\Controller;
class SomeController extends SamiController {
public function someAction () {
# $requestBody = params;
$user = params['user'];
}
}
So, the basical way for using RequestInput should aid you parsing any request body sent to a rest API.
...