A form parser for Amp's HTTP parser.

Fund package maintenance!

Installs: 8 717

Dependents: 5

Suggesters: 0

Security: 0

Stars: 11

Watchers: 6

Forks: 2

Open Issues: 2


v1.1.4 2020-03-24 20:17 UTC

This package is auto-updated.

Last update: 2021-05-27 16:29:15 UTC


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.


This package can be installed as a Composer dependency.

composer require amphp/http-server-form-parser


Basic usage works by calling parseForm($request), which will buffer the request body and parse it.


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.