amphp / http-server-form-parser
A form parser for Amp's HTTP parser.
Fund package maintenance!
amphp
Installs: 53 402
Dependents: 10
Suggesters: 0
Security: 0
Stars: 14
Watchers: 8
Forks: 5
Open Issues: 1
Language:HTML
Requires
- php: >=8.1
- amphp/amp: ^3
- amphp/byte-stream: ^2
- amphp/http: ^2
- amphp/http-server: ^3
- amphp/pipeline: ^1
- revolt/event-loop: ^1
Requires (Dev)
- amphp/log: ^2
- amphp/php-cs-fixer-config: ^2
- amphp/phpunit-util: ^3
- phpunit/phpunit: ^9
- psalm/phar: ^5.6
This package is auto-updated.
Last update: 2023-05-27 03:29:52 UTC
README
This package is an add-on to amphp/http-server
, which allows parsing request bodies as forms in either x-www-form-urlencoded
or multipart/form-data
format.
Installation
This package can be installed as a Composer dependency.
composer require amphp/http-server-form-parser
Usage
Basic usage works by calling parseForm($request)
, which will buffer the request body and parse it.
<?php use Amp\Http\Server\FormParser; use Amp\Http\Server\Request; use Amp\Http\Server\RequestHandler\CallableRequestHandler; use Amp\Http\Server\Response; use Amp\Http\Status; new CallableRequestHandler(function (Request $request) { /** @var FormParser\Form $form */ $form = yield FormParser\parseForm($request); return new Response(Status::OK, [ "content-type" => "text/plain; charset=utf-8" ], $form->getValue("text") ?? "Hello, World!"); });
There's also an advanced streaming parser included, which can be used to stream uploaded files to disk or other locations.